Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Check Voting Eligibility

Use a simple age threshold to practice if-else logic. Students trace integer input, an inclusive comparison, and the limits of this voting eligibility model.

IntermediatePhase 1 - Level 2: Nested If & Multiple ConditionsExample 6 of 10
check-voting-eligibility.py
1# Take age as input
2age = int(input("Enter age: "))
3
4# Check voting eligibility
5if age >= 18:
6 print("Eligible to vote")
7else:
8 print("Not eligible to vote")

Output

Enter age: 20
Eligible to vote

Enter age: 16
Not eligible to vote

In this one

  • Convert an age input
  • Use an inclusive threshold
  • Recognize a simplified policy

How it works

  1. 1

    Read age as an integer.

  2. 2

    Evaluate age >= 18.

  3. 3

    Print the eligible or not-eligible message.

Edge cases

Does age 18 qualify?

Does age 18 qualify?

Yes. The comparison includes eighteen.

What does a negative age do?

What does a negative age do?

It prints Not eligible to vote rather than reporting invalid input.

What's going on

This exercise models eligibility using age alone. int converts the entered response, then age >= 18 decides which of two messages to print.

A person aged eighteen passes because >= includes the boundary. A sixteen-year-old reaches else. Real voting rules may also involve citizenship, registration, and location; this short program does not check those conditions or validate a negative age.

Does age 18 qualify? Yes. The comparison includes eighteen.

What does a negative age do? It prints Not eligible to vote rather than reporting invalid input.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

Which comparison matches the code?

Pick an answer to check it.

Question 2

Does age 18 qualify?

Pick an answer to check it.

Questions people ask

Does age 18 qualify?

Yes. The comparison includes eighteen.

What does a negative age do?

It prints Not eligible to vote rather than reporting invalid input.

Which comparison matches the code?

age >= 18.