Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 10

Validate Voter Age

Easy

6 minute session

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.

Code editor
Loading editor…

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.

03:49 AM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.