Admission Price - A particular zoo determines the price of admission based on the age of the guest. Guests 2 years of age and less are admitted without charge. Children between 3 and 12 years of age cost P140.00. Seniors aged 65 years and over cost P180.00. Admission for all other guests is P230.00. Create a program that begins by reading the ages of all of the guests in a group from the user, with one age entered on each line. The user will enter a blank line to indicate that there are no more guests in the group. Then your program should display the admission cost for the group with an appropriate message. The cost should be displayed using two decimal places.
group = {0.0: [], 140.0: [], 180.0: [], 230.0: []}
print("============= Welcome to the zoo! ==============")
print("It's a great place to visit and have a fun time!")
print("For all! Big and small!")
print("Our personel gather guests in groups to guide you through the zoo.")
print("============= Welcome to the zoo! ==============")
while True:
try:
age: str = input("Enter the age of the guest (integer): ")
if age == '':
break
age_int = int(age)
assert age_int > 0
if age_int <= 2:
group[0.0].append(age_int)
elif 3 <= age_int <= 12:
group[140.0].append(age_int)
elif age_int >= 65:
group[180.0].append(age_int)
else:
group[230.0].append(age_int)
except ValueError:
print(f'WARNING: you have entered: "{age}"')
print("WARNING: Please, enter integer or blank line to exit. Try again!")
except AssertionError:
print(f'WARNING: you have entered: "{age}"')
print("WARNING: Please, enter a positive integer. Try again!")
print("Parts of the group of the ages:")
for cost in group:
print(f'in {group[cost]} pays P{cost:.2f} each,')
price = sum([cost * len(group[cost]) for cost in group])
print(f"Admission Price for the whole group: P{price:.2f}")
print(group)
Comments
Leave a comment