Question 6 of 13beginner🔧 ApplyLong Answer4 marks

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).

Correct Answer

#Program to check eligibility for driving license name = input("Enter your name: ") age = int(input("Enter your age: ")) if age >= 18: print(name, "is eligible to apply for a driving license") else: print(name, "is not eligible to apply for a driving license")

Output: Enter your name: Rahul Enter your age: 19 Rahul is eligible to apply for a driving license

Exercise: PROGRAMMING EXERCISES | Q: 1
For More Understanding

Explanation

The program uses the if..else selection structure to check eligibility. The input() function takes the name as a string and age as an integer. The condition age >= 18 is checked - if true, the indented block under if executes; otherwise, the block under else executes. This follows the syntax shown in the textbook for if..else statements where two alternative paths are provided based on the condition.

Solution Steps

  1. Step 1: Accept name from user using input() function

  2. Step 2: Accept age from user and convert to integer using int(input())

  3. Step 3: Use if statement to check if age >= 18

  4. Step 4: If condition is true, print eligibility message

  5. Step 5: If condition is false, print ineligibility message using else block