Knowee
Questions
Features
Study Tools

Check whether the person is eligible for a driving license or not. If the age is less than 18, throw an exception and print "InvalidAge" and quit. If the score is less than 40, throw an exception and print "You should get at least 40 marks" and quit. Else print"Passed".Input FormatThe input consists of the age and score separated by a space.Output FormatThe output prints the age, score, and result.Refer to the sample outputs for the formatting specifications.Sample Input12 50Sample OutputInvalid age

Question

Check whether the person is eligible for a driving license or not. If the age is less than 18, throw an exception and print "InvalidAge" and quit. If the score is less than 40, throw an exception and print "You should get at least 40 marks" and quit. Else print"Passed".Input FormatThe input consists of the age and score separated by a space.Output FormatThe output prints the age, score, and result.Refer to the sample outputs for the formatting specifications.Sample Input12 50Sample OutputInvalid age

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This problem can be solved using Python. Here is a step-by-step solution:

  1. First, we need to take the input from the user. The input will be a string containing the age and score separated by a space. We can use the input() function to get the user input and the split() function to split the input into age and score.
age, score = map(int, input().split())
  1. Next, we need to check if the age is less than 18. If it is, we throw an exception and print "Invalid age". We can use an if statement to check the age and the raise keyword to throw an exception.
if age < 18:
    raise Exception("Invalid age")
  1. If the age is not less than 18, we then check if the score is less than 40. If it is, we throw an exception and print "You should get at least 40 marks". We can use another if statement to check the score and the raise keyword to throw another exception.
if score < 40:
    raise Exception("You should get at least 40 marks")
  1. If neither of the conditions are met, we print "Passed".
print("Passed")

Here is the complete code:

age, score = map(int, input().split())

if age < 18:
    raise Exception("Invalid age")

if score < 40:
    raise Exception("You should get at least 40 marks")

print("Passed")

This code will take the age and score as input, check if the person is eligible for a driving license, and print the appropriate message.

This problem has been solved

Similar Questions

Develop a Java program to determine the eligibility of applicants for adriving license based on their age and driving experience. Prompt the user toinput their age and the number of years they have held a driving license. Usecontrol statements to check if the applicant meets the minimum agerequirement (e.g., 18 years) and has sufficient driving experience (e.g., atleast 2 years). Implement operators to perform the necessary comparisonsand logical operations. Display appropriate messages to inform the userwhether they are eligible for a driving license or not based on the conditionsmet.

Write the output of the program below. age = 45if (age >= 35): {print ("I am Qualified")}

Enter the student details using constructors with arguments and constructors without arguments. Then find the total marks of each student. If it is greater than 500 print pass , else print fail.Input:1Neha123456A100100100100100100outputNeha123456A100100100100100100Pass

Problem StatementBuild a program for a small town where individuals are eligible to vote only if they are 18 years or older. Take the age of a person as input and indicate their eligibility. If the age is 18 or above, print "Eligible for Voting"; otherwise, print "Not eligible for Voting" using the ternary operator.Input format :The input is an integer n, representing the age of the person.Output format :The output displays either "Eligible for Voting" or "Not eligible for Voting" based on age.Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the test cases will fall under the following constraints:1 ≤ n ≤ 100Sample test cases :Input 1 :18Output 1 :Eligible for VotingInput 2 :37Output 2 :Eligible for VotingInput 3 :12Output 3 :Not eligible for VotingInput 4 :9Output 4 :Not eligible for Voting

Complete the main method in the AgeChecker class by Declaring and instantiating a Scanner objectPrint the "What is your age?" message to the consoleDeclaring the int age variable, assigning it the output of nextInt()If the value of age is greater than 40 then print "You are old". Otherwise, print "You are young"

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.