Check Eligibility to Vote in Python
18 or older. Negative age is garbage, not "not eligible".
BeginnerConditional ProgramsExample 4 of 20
check-eligibility-to-vote.py
1# Program to check voting eligibility23age = int(input("Enter your age: "))45if age < 0:6 print("Age cannot be negative.")7elif age >= 18:8 print("You are eligible to vote.")9else:10 print("You are not eligible to vote yet.")
Output
Enter your age: 17 You are not eligible to vote yet.
In this one
- >= 18, not > 18
- negative age is invalid, not a no
What's going on
age >= 18. That's the law this file pretends to know.
Negative age is not "not eligible yet". It's a bad input. Handle it first or you print a polite lie.
17 prints "not eligible yet". 18 prints eligible. Off-by-one here is a real-world bug.
After this program
If the idea is still fuzzy, read Day 8: Conditional Statements in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 20 conditional programs, or see every topic on Python exercises.