Answer to Question #239372 in Python for ggg

Question #239372

In the Happy Valley School System, children are classified by age as follows: less than 2, ineligible 2, toddler 3-5, early childhood 6-7, young reader 8-10, elementary 11 and 12, middle 13, impossible 14-16, high school 17-18, scholar greater than 18, ineligible Given an int variable age, write a switch statement that prints out, on a line by itself, the appropriate label from the above list based on age





1
Expert's answer
2021-09-20T00:11:56-0400
def displayInfo(argument):
    switcher = {
        range(1, 2): "ineligible",
        2: "toddler ",
        range(3,6): "early childhood",
        range(6,8): "young reader",
        range(8,11): "elementary",
        range(11,13): "middle",
        13: "impossible",
        range(14,17): "high school",
        range(17,19): "scholar",
        range(19,100000): "ineligible"
    }
    
    for key in switcher:
        if type(key) is range and argument in key:
            print(switcher[key])
            return
        elif type(key) is not range and argument == key:
            print(switcher[argument])
            return
            
    print("Wrong age")




displayInfo(int(input("Enter age: ")))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS