Python Data Structures - Ticket Office | Sololearn: Learn to code for FREE!


Python Data Structures - Ticket Office

My code looks right to me, but my answers are a little off. Where is the mistake in my code? Task: 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). My solution:

6/26/2021 5:40:40 PM


5 Answers

New Answer


you have to be keen on your declarations. new is set to 0 and old is set to 530 accord g to the question. then use for loop and the rest will work out 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)


@Jayakrishna🇮🇳 The change to int(change) didn't work. The answer is close but off. For test case 1, if the input is 16, the output should be 5. I got 6. For test case 2, if the input is 10, the output should be 31. I got 34.


Code is truncated.. save in playground and share link here .. edit: Sid thank for edit. looks fine. try again by just editing last line to : (convert to int) print(int(change))


You are calculating with 25 for an adult, but should be 20!!! then it works fine.


Sid yes. As @Angela pointed , you are using 25 instead of 20 for adult. So that may be problem ...