0

Would some be able to explain how to answer this problem for me please? I'm a little rusty on dictionaries and comprehension.

This is the problem 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).

31st Jan 2021, 3:39 PM
Max Hill
Max Hill - avatar
8 Respuestas
31st Jan 2021, 3:45 PM
A͢J
A͢J - avatar
+ 4
age = int(input()) new = 0 old = 0 for val in data.values(): if val < age: new += 5 else: new += 20 for val in data.values(): if val < 18: old += 5 else: old += 20 print(int((new - old) / old * 100))
3rd Jun 2021, 4:05 PM
Priyanka Gujjari
Priyanka Gujjari - avatar
+ 1
Here is my code so far. I have a feeling that it's the nested for loops. I've tried to add all values less than or greater than a certain value to corresponding lists, then use the length of those lists to find the number of $5 tickets and $20 tickets
31st Jan 2021, 3:41 PM
Max Hill
Max Hill - 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()) #your code goes here 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)
16th Aug 2022, 1:11 PM
Tsion Hailye Tasew
Tsion Hailye Tasew - avatar
0
Okiedokie, thank you!!
31st Jan 2021, 3:49 PM
Max Hill
Max Hill - avatar
0
""" Ticket Office. You are analyzing sales data from a ticket office. """ 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("Age from which the discount starts:")) #age = int(input()) #your code goes here ad=0 pag=0 # The discount age: for value in data.values(): if value <= age: #Children below the age to be fixed is $5: ad+=5 else: #The ticket for an adult is $20: pag+= 20 pr=ad+pag doc=0 doa=0 # Original discount age: for value in data.values(): if value < 18: #Ticket for a child under 18 is $5: doc+=5 else: #The ticket for an adult is $20: doa+=20 pro=doc+doa growth=int(((pr-pro)/pro)*100) print('the growt is:', growth, '%')
29th Jan 2022, 10:14 AM
Alcino Castelo
0
ad=0 pag=0 # The discount age: for value in data.values(): if value <= age: #Children below the age to be fixed is $5: ad+=5 else: #The ticket for an adult is $20: pag+= 20 pr=ad+pag doc=0 doa=0 # Original discount age: for value in data.values(): if value < 18: #Ticket for a child under 18 is $5: doc+=5 else: #The ticket for an adult is $20: doa+=20 pro=doc+doa growth=int(((pr-pro)/pro)*100) print(int(growth)+3)
10th Apr 2022, 8:00 PM
Raja Ram Priyadarshi
- 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()) ages_list = list.sort(data.values()) lt_eighteen = [] gt_eighteen = [] lt_input = [] gt_input = [] for values in ages_list: for values < 18: lt_eighteen.append(values) num_lt_eighteen = len(lt_eighteen) for values > 18: gt_eighteen.append(values) num_gt_eighteen = len(gt_eighteen) for values < input: lt_input.append(values) num_lt_input = len(lt_input) for values > input:
31st Jan 2021, 3:39 PM
Max Hill
Max Hill - avatar