Python Nozioni di baseFacile

Quadranti in cui giace una data coordinata

Guida dettagliata e implementazione Python per il problema "Quadroni in cui si trova una data coordinata".

Dichiarazione del problema

Facile

Scrivi una funzione find_quadrant(x, y) che accetta due interi x e y che rappresentano un punto sul piano cartesiano e restituisce una stringa che indica in quale quadrante si trova il punto.

Ritorno:

- 'Quadrante 1' se x > 0 e y > 0

- 'Quadrante 2' se x < 0 e y > 0

- 'Quadrante 3' se x < 0 ey < 0

- 'Quadrante 4' se x > 0 e y < 0

- 'Origine' se x == 0 e y == 0

- 'Asse X' se y == 0 e x != 0

- 'Asse Y' se x == 0 e y != 0

Vincoli
  • -10^4 <= x, y <= 10^4

Esempi

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?
Prendi in considerazione l'utilizzo di strutture dati specifiche di Numbers come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

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

Apri nell'editor
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

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.