+ 4

Ticket Office in python, Why?

"""You are analyzing sales data from a ticket office. The ticket for an adult is $20, while the ticket for a child under 18 is $5. The data you are given is in a dictionary format, where the keys are the sold ticket numbers, and the values are the customer ages. For example, "123-08": 24 means that the ticket was bought a 24 year old. Your goal is to calculate how much more money the office would make if it would change the ticket discount age to the given input. So, your program needs to take an integer as input and output the percentage of revenue growth, if the discount was given to people under that age. For example, if the office made $15000 with the original discount age, and would make $18000 with 14 as the discount age, then the growth would be ((18000-15000)/15000)*100 = 20% So, for the input 14, your program should output 20. The output should be an integer (use int() to convert the result).""" data = { "100-90": 25, "42-01": 48, "55-09": 12, "128-64": 71, "002-22": 18, "321-54": 19, "097-32": 33, "065-135": 64, "99-043": 80, "111-99": 11, "123-019": 5, "109-890": 72, "132-123": 27, "32-908": 27, "008-09": 25, "055-967": 35, "897-99": 44, "890-98": 56, "344-32": 65, "43-955": 59, "001-233": 9, "089-111": 15, "090-090": 17, "56-777": 23, "44-909": 27, "13-111": 21, "87-432": 15, "87-433": 14, "87-434": 23, "87-435": 11, "87-436": 12, "87-437": 16, "94-121": 15, "94-122": 35, "80-089": 10, "87-456": 8, "87-430": 40 } age = int(input()) # your code goes here by Kushal Bhoopalam new = 0 old = 530 for var in data.values(): if var < age: new += 5 else: new += 20 if age < 18: print(int((new - old) / old * 100)) else: print(0) #why old = 530 ???, Please help me know!

27th Mar 2021, 12:42 AM
Hieu Tran Thanh
Hieu Tran Thanh - avatar
7 ответов
+ 1
If you do the same calculation to get 'new' with the age as 18, you get the value for 'old' as 530. Which you should know, because you were supposed to have calculated this value yourself in your code.
27th Mar 2021, 1:57 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
instead of hardcoding value of old let your program calculate it age = int(input()) new = 0 old = 0 for x in data.values(): old += 5 if x < 18 else 20 for var in data.values(): new += 5 if var < age else 20 if age < 18: print(int((new - old) / old * 100)) else: print(0)
16th May 2021, 1:28 PM
Pranay Sondkar
Pranay Sondkar - avatar
+ 2
Ok. I fixed it
27th Mar 2021, 1:59 AM
Hieu Tran Thanh
Hieu Tran Thanh - avatar
+ 1
for var in data.values(): new +=5 if var < 18 else 20
27th Mar 2021, 2:27 AM
Hieu Tran Thanh
Hieu Tran Thanh - avatar
+ 1
Thank you.
27th Mar 2021, 2:28 AM
Hieu Tran Thanh
Hieu Tran Thanh - avatar
+ 1
data = { "100-90": 25, "42-01": 48, "55-09": 12, "128-64": 71, "002-22": 18, "321-54": 19, "097-32": 33, "065-135": 64, "99-043": 80, "111-99": 11, "123-019": 5, "109-890": 72, "132-123": 27, "32-908": 27, "008-09": 25, "055-967": 35, "897-99": 44, "890-98": 56, "344-32": 65, "43-955": 59, "001-233": 9, "089-111": 15, "090-090": 17, "56-777": 23, "44-909": 27, "13-111": 21, "87-432": 15, "87-433": 14, "87-434": 23, "87-435": 11, "87-436": 12, "87-437": 16, "94-121": 15, "94-122": 35, "80-089": 10, "87-456": 8, "87-430": 40 } age = int(input()) main = 0 new = 0 for original in data.values(): if original >= 18: main += 20 else: main += 5 main_total = main for change in data.values(): if change >= age: new += 20 else: new += 5 new_total = new Growth = (new_total - main_total) / main_total * 100 print(int(Growth))
19th Nov 2022, 12:35 AM
Mohamed Gomaa Soliman
0
#A simple and effective code age = int(input()) #your code goes here new = 0; old = 0; for i in data.values(): old += 5 if i<18 else 20 new +=5 if i<age else 20 print(int(((new - old)/old)*100))
26th Sep 2022, 5:41 AM
Bhoot Singh
Bhoot Singh - avatar