Check Eligibility to Vote
Check if a person is eligible to vote based on age (18 or older).
BeginnerTopic: Conditional Programs
What You'll Learn
- Applying comparison operators with integers
- Handling invalid input ranges
- Using elif for cleaner branching
Python Check Eligibility to Vote Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to check voting eligibility
age = int(input("Enter your age: "))
if age < 0:
print("Age cannot be negative.")
elif age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote yet.")Output
Enter your age: 17 You are not eligible to vote yet.
Step-by-Step Breakdown
- 1Read age as an integer.
- 2If age is negative, show an error.
- 3Else if age is at least 18, mark eligible.
- 4Otherwise, mark not eligible.
Understanding Check Eligibility to Vote
We assume a minimum voting age of 18:
•Negative ages are invalid and handled first.
•18 or older → eligible.
•Below 18 → not yet eligible.
This is a classic example of simple threshold-based decision making.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.