Voting Age
Python Coding Problems
Conditional Statements
Loops & Iterations
Data Lists & Collections
Area Calculator
Grade Calculator
Make a Username
Voting Age
Multiplication Table
Factorial
Say Hello
Palindrome
Random Number
To-Do List
Voting Age
Topic: Voting Age Eligibility Checker
Description: This program takes a user's age as an input and determines whether they are legally eligible to vote (minimum age of 18). If they are eligible, it welcomes them to the electoral system. If they are not, it calculates exactly how many years they must wait before they can register.
Why: This program teaches students the basics of **comparison operators** (>=) and **arithmetic operations** within conditional blocks. It introduces the concept of structural data branching—where the program performs entirely distinct calculations based on a variable's state.
Program Code
Copy and run the following Python code to see the eligibility system in action:
def check_voting_eligibility(): print("=============================") print(" VOTING ELIGIBILITY SYSTEM ") print("=============================") VOTING_AGE = 18 try: # Capture and sanitize user age input user_age = int(input("Enter your age: ").strip()) except ValueError: print("\nError: Please enter a valid whole number for age.") return # Check condition constraints if user_age < 0: print("\nInvalid Input: Age cannot be a negative number.") elif user_age >= VOTING_AGE: print("\n-----------------------------") print(" REGISTRATION STATUS ") print("-----------------------------") print("Status : ELIGIBLE TO VOTE") print("Message : You are legally old enough to participate in elections.") print("-----------------------------") else: # Calculate remaining years to eligibility years_waiting = VOTING_AGE - user_age print("\n-----------------------------") print(" REGISTRATION STATUS ") print("-----------------------------") print("Status : NOT ELIGIBLE") print(f"Message : You must wait {years_waiting} more year(s) to register.") print("-----------------------------") # Execute the registration check check_voting_eligibility()
Expected Console Output Examples
Example 1 (Eligible Voter Profile):
=============================
VOTING ELIGIBILITY SYSTEM
=============================
Enter your age: 21
-----------------------------
REGISTRATION STATUS
-----------------------------
Status : ELIGIBLE TO VOTE
Message : You are legally old enough to participate in elections.
🏋️ Test Yourself With Exercises
Take our quiz on Voting Age to test your knowledge.
Browse Quizzes »