Lesson guide
What this Python exercise practices
Validate Voter Age is a beginner practice lesson that focuses on functions, parameters, return values. It is designed to be solved in about 6 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Function parameters
- Return values
Difficulty and time
- Level
- Beginner
- Estimated time
- 6 minutes
Summary
Check whether a person is old enough to vote (18+).
Problem statement
Write a function is_eligible_voter(age) that takes an integer age and returns True if the age is 18 or older (eligible to vote), otherwise returns False. Handle unexpected ages (e.g., negative values) by returning False.
Task
Use if/else to return True when age is 18 or older, otherwise return False.
Examples
Simple eligibility
Input
18
Output
True
Explanation
Age 18 is eligible.
Input format
A single integer argument: age.
Output format
Return a boolean: True if age >= 18, otherwise False.
Constraints
Age will be an integer. Treat negative ages as not eligible.
Samples
Sample input 0
20
Sample output 0
True
Explanation 0
20 is >= 18, so eligible.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.