Lesson guide
What this Python exercise practices
Determine Cartesian Quadrant is a intermediate practice lesson that focuses on functions, parameters, return values. It is designed to be solved in about 14 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Function parameters
- Return values
Difficulty and time
- Level
- Intermediate
- Estimated time
- 14 minutes
Summary
Given x and y coordinates, determine which Cartesian quadrant (or axis/origin) the point lies in.
Problem statement
Write a function determine_quadrant(x, y) that returns a string indicating where the point (x, y) lies: - Return 'Q1' if x > 0 and y > 0. - Return 'Q2' if x < 0 and y > 0. - Return 'Q3' if x < 0 and y < 0. - Return 'Q4' if x > 0 and y < 0. - If the point is on the x-axis (y == 0 but x != 0), return 'X axis'. - If the point is on the y-axis (x == 0 but y != 0), return 'Y axis'. - If the point is at the origin (0, 0), return 'Origin'. Use if/elif/else to implement the logic.
Task
Practice multi-branch decision making using if, elif, and else to return the correct quadrant label or axis/origin description.
Examples
Point in first quadrant
Input
determine_quadrant(3, 4)
Output
Q1
Explanation
Both x and y are positive, so the point is in quadrant 1.
Input format
Two integers x and y passed to the function determine_quadrant(x, y).
Output format
A string among: 'Q1', 'Q2', 'Q3', 'Q4', 'X axis', 'Y axis', or 'Origin'.
Constraints
x and y are integers. Use only basic control flow (if/elif/else).
Samples
Sample input 0
determine_quadrant(-2, 3)
Sample output 0
Q2
Explanation 0
x is negative and y is positive, so quadrant 2.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.