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

Расширьте свои знания с помощью соответствующих интерактивных руководств, шпаргалок и сравнений кода.

Учебник по Python

Объяснение переменных и типов данных Python

Понимать переменные Python и основные типы данных (строки, целые числа, числа с плавающей запятой, логические значения). Полное руководство для начинающих по распределению памяти в Python.

Посмотреть ресурс
Практическое руководство

Как отсортировать список в Python

Узнайте, как сортировать список в Python с помощью метода sort() и функции sorted(). Ознакомьтесь с примерами пользовательской сортировки ключей и обратного порядка.

Посмотреть ресурс
Шпаргалка

Шпаргалка по строковым методам Python

Полное справочное руководство по манипулированию строками в Python. Мастер форматирования, поиска, разделения, замены и проверки свойств строк.

Посмотреть ресурс
Сравнение языков

Python против JavaScript: какой язык программирования лучше?

Всестороннее сравнение Python и JavaScript. Изучите синтаксические различия, производительность, варианты использования (серверная и клиентская части) и примеры кодирования.

Посмотреть ресурс