Python Practice › If-Else Programs › Program 15
Check voting eligibility
Write a Python program to check whether a person is eligible to vote (age 18 or above).
Input
17, 18, 45
Output
17 -> not eligible, wait 1 year(s) 18 -> eligible to vote 45 -> eligible to vote
Approach
- Compare the age with 18 using
>=.
Solution
for age in [17, 18, 45]: if age >= 18: print(age, "-> eligible to vote") else: print(age, "-> not eligible, wait", 18 - age, "year(s)")Output
17 -> not eligible, wait 1 year(s) 18 -> eligible to vote 45 -> eligible to vote
Line by line
Line 2
>= includes exactly 18, which is the legal voting age in India.
Line 5
The else branch also tells how long to wait.
Learn the concept
New to this topic? Read the lesson, then come back.