Worked Examples · Example 6.1
Q.If the age entered by the user is greater than 18, then print that the user is eligible to vote. (If the condition is true, the indented statement(s) are executed.)
Odisha ChseTextbookSubjective· 2mImportance★★★★★est
3% · 1/39 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →This is the simplest form of selection — a lone if whose indented statement runs only when the condition (age qualifies for voting, i.e. 18 or above) is True; otherwise nothing happens.
The idea. The example demonstrates one-way selection: an if with no else. When the condition is True, Python executes the indented statement(s); when False, it skips them and continues after the if — here, the program just ends silently.
Program
age = int(input("Enter your age: "))
if age >= 18:
print("Eligible to vote")
Sample runs
Enter your age: 20
Eligible to vote
Enter your age: 10
(For 10, the condition fails, the indented print is skipped, and there is no output at all — exactly the behaviour of an if without else.)
Key points.
- input() returns a string; int() converts it so the numeric comparison works.
- The indentation (the print line shifted right) is what marks the statement as belonging to the if — this is Python's block syntax. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.