Determine Quadrant
Locate a point in a quadrant, on an axis, or at the origin. Students trace Python sign comparisons and see why zero coordinates need separate branches.
1# Take coordinates2x = float(input("Enter x coordinate: "))3y = float(input("Enter y coordinate: "))45# Determine quadrant6if x > 0 and y > 0:7 print("Quadrant I")8elif x < 0 and y > 0:9 print("Quadrant II")10elif x < 0 and y < 0:11 print("Quadrant III")12elif x > 0 and y < 0:13 print("Quadrant IV")14elif x == 0 and y == 0:15 print("Origin")16elif x == 0:17 print("On Y-axis")18else:19 print("On X-axis")
Output
Enter x coordinate: 3 Enter y coordinate: 4 Quadrant I Enter x coordinate: -2 Enter y coordinate: 5 Quadrant II
In this one
- Read coordinate signs
- Distinguish axes and quadrants
- Handle the origin first
How it works
- 1
Read x and y as floats.
- 2
Try the four nonzero sign combinations.
- 3
Then distinguish origin, Y-axis, and X-axis.
Edge cases
Where is (-2, 5)?
Where is (-2, 5)?
Quadrant II: x is negative and y is positive.
Where is (0, 0)?
Where is (0, 0)?
Origin; its special branch comes before the axis branches.
What's going on
A quadrant depends on both coordinate signs. Four and conditions cover the four nonzero sign combinations in counterclockwise order, starting with positive x and positive y.
If none matches, at least one coordinate is zero. The origin is tested before either single-axis case so (0, 0) gets its own label. Otherwise x equal to zero means the Y-axis; the remaining case is the X-axis.
Where is (-2, 5)? Quadrant II: x is negative and y is positive.
Where is (0, 0)? Origin; its special branch comes before the axis branches.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What places a point on the Y-axis?
Pick an answer to check it.
Question 2
Where is (-2, 5)?
Pick an answer to check it.
Questions people ask
Where is (-2, 5)?
Quadrant II: x is negative and y is positive.
Where is (0, 0)?
Origin; its special branch comes before the axis branches.
What places a point on the Y-axis?
x == 0.
๐Related Content
- ๐
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- ๐
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- ๐ป
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum