Create a function of name check_age(). The function will receive age of a child. If the age is less than 6, then the function return “Invalid age”. If the age is less than 9, then the function return “This age is eligible for primary school”. If the age is greater than or equal to 9, then the function return “This age is not eligible for primary school”.
Question
Create a function of name check_age(). The function will receive age of a child. If the age is less than 6, then the function return “Invalid age”. If the age is less than 9, then the function return “This age is eligible for primary school”. If the age is greater than or equal to 9, then the function return “This age is not eligible for primary school”.
Solution
def check_age(age):
if age < 6:
return "Invalid age"
elif age < 9:
return "This age is eligible for primary school"
else:
return "This age is not eligible for primary school"
Step-by-Step Explanation:
-
Define the Function: Start by defining a function named
check_agethat takes one parameter,age. -
First Condition: Check if the age is less than 6.
- If true, return the string "Invalid age".
-
Second Condition: If the first condition is false, check if the age is less than 9.
- If true, return the string "This age is eligible for primary school".
-
Else Condition: If both previous conditions are false, it means the age is 9 or greater.
- Return the string "This age is not eligible for primary school".
Similar Questions
entry is invalid, 1 if they are under the age limit or 2 if they are over the age limit. The function is shown below. The variables age and agelimit will both be integers.01 function checkage(age, agelimit):02 if age < 0 then03 return 004 elseif age < 38 then05 return 106 else:07 return 208 endif09 end functionThe code executes, but it does not give the correct result when called with: checkage(30, 20)The function returns 1, but it should return 2. State the type of error in the code and explain the change that needs to be made for the function to work.[3]
Write a program to check whether a person is eligible for voting or not. (accept age from user)
This script checks whether a person is eligible for voting or not. Which variable is most appropriate for line 2?1 age=int(input("Enter your age"))2 if ___ >=18:3 print("_____ for voting")4 ____:5 print("not eligible for voting")agevotenameprint
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"
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
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.