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
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: ")))
Comments
Leave a comment