Check Voting Eligibility
Use a simple age threshold to practice if-else logic. Students trace integer input, an inclusive comparison, and the limits of this voting eligibility model.
1# Take age as input2age = int(input("Enter age: "))34# Check voting eligibility5if age >= 18:6 print("Eligible to vote")7else:8 print("Not eligible to vote")
Output
Enter age: 20 Eligible to vote Enter age: 16 Not eligible to vote
In this one
- Convert an age input
- Use an inclusive threshold
- Recognize a simplified policy
How it works
- 1
Read age as an integer.
- 2
Evaluate age >= 18.
- 3
Print the eligible or not-eligible message.
Edge cases
Does age 18 qualify?
Does age 18 qualify?
Yes. The comparison includes eighteen.
What does a negative age do?
What does a negative age do?
It prints Not eligible to vote rather than reporting invalid input.
What's going on
This exercise models eligibility using age alone. int converts the entered response, then age >= 18 decides which of two messages to print.
A person aged eighteen passes because >= includes the boundary. A sixteen-year-old reaches else. Real voting rules may also involve citizenship, registration, and location; this short program does not check those conditions or validate a negative age.
Does age 18 qualify? Yes. The comparison includes eighteen.
What does a negative age do? It prints Not eligible to vote rather than reporting invalid input.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which comparison matches the code?
Pick an answer to check it.
Question 2
Does age 18 qualify?
Pick an answer to check it.
Questions people ask
Does age 18 qualify?
Yes. The comparison includes eighteen.
What does a negative age do?
It prints Not eligible to vote rather than reporting invalid input.
Which comparison matches the code?
age >= 18.
๐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