Python GrundlagenEinfach

Quadranten, in denen eine bestimmte Koordinate liegt

Detaillierte Anleitung und Python-Implementierung für das Problem „Quadranten, in denen eine bestimmte Koordinate liegt“.

Problemstellung

Einfach

Schreiben Sie eine Funktion find_quadrant(x, y), die zwei Ganzzahlen x und y annimmt, die einen Punkt auf der kartesischen Ebene darstellen, und eine Zeichenfolge zurückgibt, die angibt, in welchem Quadranten der Punkt liegt.

Rückgabe:

- 'Quadrant 1', wenn x > 0 und y > 0

- 'Quadrant 2', wenn x < 0 und y > 0

- 'Quadrant 3', wenn x < 0 und y < 0

- 'Quadrant 4', wenn x > 0 und y < 0

- 'Ursprung' wenn x == 0 und y == 0

- 'X-Achse' wenn y == 0 und x != 0

- 'Y-Achse' wenn x == 0 und y != 0

Einschränkungen
  • -10^4 <= x, y <= 10^4

Beispiele

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?
Erwägen Sie die Verwendung von Numbers-spezifischen Datenstrukturen wie Mengen oder Heaps.
Edge Cases to Watch
  • Leere Eingabestrukturen
  • Einzelelementeingaben
  • Große numerische Grenzen

Bereit zur Lösung?

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

Im Editor öffnen
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

Empfohlene Python-Ressourcen

Erweitern Sie Ihr Wissen mit zugehörigen interaktiven Tutorials, Spickzetteln und Codevergleichen.