Q.Write a program that takes the name and age of the user as input and displays a message whether the user is eligible to apply for a driving license or not. (the eligible age is 18 years).
Take name and age as input, convert age to int, and use a two-way if–else on the single condition age >= 18 to print eligible / not eligible.
The idea. This is a classic two-way selection: exactly one condition (is the user at least 18?) splits execution into two mutually exclusive paths, which is precisely what if–else expresses. The only subtlety is that input() always returns a string, so the age must pass through int() before a numeric comparison.
Algorithm
- Input name (string).
- Input age and convert to integer.
- If age >= 18, display the eligible message; otherwise display the not-eligible message.
Program
name = input("Enter your name: ")
age = int(input("Enter your age: "))
if age >= 18:
print(name + ", you are eligible to apply for a driving license.")
else:
print(name + ", you are not eligible to apply for a driving license.")
Sample runs
Enter your name: Riya
Enter your age: 19
Riya, you are eligible to apply for a driving license.
Enter your name: Aman
Enter your age: 16
Aman, you are not eligible to apply for a driving license.
Boundary check: an exactly-18-year-old user satisfies age >= 18, so 18 correctly counts as eligible ("the eligible age is 18 years").
Writing age > 18 instead of age >= 18 wrongly rejects someone who is exactly 18 — always test the boundary value.
The program reads name and age, and if age >= 18 prints that the user is eligible to apply for a driving license, otherwise that they are not (e.g. Riya, 19 → eligible; Aman, 16 → not eligible).
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.