Python Basics簡単

Quadrants in which a given coordinate lies

Detailed guide and Python implementation for the 'Quadrants in which a given coordinate lies' problem.

問題提起

簡単

Write a function find_quadrant(x, y) that takes two integers x and y representing a point on the Cartesian plane and returns a string indicating which quadrant the point lies in.

Return:

- 'Quadrant 1' if x > 0 and y > 0

- 'Quadrant 2' if x < 0 and y > 0

- 'Quadrant 3' if x < 0 and y < 0

- 'Quadrant 4' if x > 0 and y < 0

- 'Origin' if x == 0 and y == 0

- 'X-Axis' if y == 0 and x != 0

- 'Y-Axis' if x == 0 and y != 0

制約
  • -10^4 <= x, y <= 10^4

Example 1
Input
find_quadrant(3, 5)
Output
'Quadrant 1'
Explanation

Both x=3 and y=5 are positive, so the point is in Quadrant 1 (upper-right).

Example 2
Input
find_quadrant(-2, 4)
Output
'Quadrant 2'
Explanation

x=-2 is negative and y=4 is positive, so the point is in Quadrant 2 (upper-left).

Example 3
Input
find_quadrant(-1, -7)
Output
'Quadrant 3'
Explanation

Both x=-1 and y=-7 are negative, so the point is in Quadrant 3 (lower-left).

Need a Hint?
Consider using Numbers-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

解決する準備はできましたか?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

エディタで開く
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推奨される Python リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。