+ 3

Ticket Office problem

Hi, I don't understand the problem can anyone please explain to me what to do? Here are the instructions. 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). Please help!!!!

31st Mar 2021, 1:09 AM
Ailana
Ailana - avatar
21 Antworten
+ 4
They're considering to change the age range for a discount and want to know how much that affects the money they bring in. The solution I used was: 1. calculate the total assuming the discount is for under 18. 2. calculate the total assuming the discount is only for under the specified age. 3. print the difference * 100 / step 2's total. The example they gave with 14 and 20 is confusing because that doesn't match the data specified in the question. An age of 14 won't lead to a difference percentage of 20. I forget what it leads to but not 20. I recommend just doing the above steps and basically ignore the confusing example they give.
31st Mar 2021, 1:49 AM
Josh Greig
Josh Greig - avatar
+ 3
This is a tough one because instructions weren't clear for me either. However, I figured it out. I'll talk over the problem for you but not provide you working code. Ask questions if you still need input. BASE CALCS You need to calculate ticket sales based on over/under 18 yrs old. We use that to calculate the total of all sales (child+adult) and let's call that BASE. MODEL CALCS Then you calculate the total ticket sales given AGE as INPUT(). Now you know how much you collected with the MODEL. Use their formula to calculate the percentage. ((BASE-MODEL)/MODEL)*100 Then print the percentage. I hope this helps.
31st Mar 2021, 1:46 AM
Jerry Hobby
Jerry Hobby - avatar
+ 3
Ailana wrote, "Why would the old variable have 530??" Response: old represents the current total cash from ticket sales in his program. In other words, old represents the total ticket sale revenue when everyone under 18 gets the discounted price of $5. Since that value doesn't depend on user input, it could be hard-coded to 530. You can manually calculate it yourself by counting all the ages under 18 and multiplying by 5. Find all the ages 18 or greater and multiply that by 20. Do it manually to start with so it'll make more sense. To manually calculate it, look at the data variable and the values set in it. Every key-value pair represents an a ticket. The value is the customer's age in years. The first ticket is purchased by someone aged 25 and since 25 >= 18, he/she would have paid $20. Go through the remaining 30 or so tickets and find the total. If you get stuck counting it manually, the numbers should work out to 5 * 14 + 20 * 23 which is 530. I shared a Python script below that also shows this calculation for you. 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 } without_adjustment = 0 with_discount =0 without_discount =0 for a in data.values(): if a < 18: without_adjustment += 5 with_discount += 1 else: without_adjustment += 20 without_discount += 1 print('without_adjustment = ' + str(without_adjustment) + ', with discount: ' + str(with_discount) + ', without discount: ' + str(without_discount))
1st Apr 2021, 8:26 PM
Josh Greig
Josh Greig - avatar
+ 3
Hi Jerry Hobby, I made the question, then I realised later that the keys in this dictionary may be like a serial number for each ticket. I thought that the number within the string in key would have a meaning. But the solution doesn't even need the values within the string.
23rd May 2021, 12:36 AM
Lucas Kliemczak
Lucas Kliemczak - avatar
+ 2
Ailana wrote, "I don't understand...." Response: I guess we beat around the bush for a day which is about enough then. Here is someone's solution: https://code.sololearn.com/csC2v4j1Uq8D/#py He hardcoded the "old" variable to 530. My suggestion was to calculate it in the loop in step 1 of my previous answer. Either way works. What he calls "new" is the result of step 2 from my suggestion. Try to make sense of it and learn from it instead of merely copying and moving on.
1st Apr 2021, 1:04 AM
Josh Greig
Josh Greig - avatar
+ 2
age = int(input()) total_first=0 total_second=0 for value in data.values(): if value<18: total_first+=5 if value>=18: total_first+=20 for value in data.values(): if value<age: total_second+=5 if value>=age: total_second+=20 x=int(((total_second-total_first)/total_first)*100) print(x)
6th Sep 2021, 6:37 AM
Hossein Razghandi
Hossein Razghandi - avatar
+ 1
The objective is to calculate total sales for age 18. Then calculate when the age is something else. Let’s say 14. If you charge 14 and higher full price then you’ll collect more money than if only 18 and up are charged as adults. The task is to calculate both totals of ticket sales. compare them. Then calculate it as a percentage. That’s where the formula comes in. Build it in three steps. Calculate BASE. Calculate MODEL the same way, but using the specified AGE. Finally calculate the percentage using their formula. Output the percentage.
31st Mar 2021, 11:54 PM
Jerry Hobby
Jerry Hobby - avatar
+ 1
For each seat in the dictionary, it contains the age of the person. When you add up the seats according too the price for that age, that’s the number you’re after. If under AGE then child, if equal or over AGE then adult fair. Calculate total sales.
1st Apr 2021, 6:33 PM
Jerry Hobby
Jerry Hobby - avatar
+ 1
Please try to solve it then show us your effort.
1st Apr 2021, 6:33 PM
Jerry Hobby
Jerry Hobby - avatar
+ 1
Jerry Hobby, I also didn't understand this problem because I don't know what this dictionary means. The values are ages, ok. But I didn't understand the meaning of the keys. The statement says that it is the number of tickets, but there are 2 numbers in format of string among the keys.
21st May 2021, 1:47 AM
Lucas Kliemczak
Lucas Kliemczak - avatar
+ 1
Lucas Kliemczak A dictionary is a Python data type. A dictionary is an array that is indexed by key values. People = { "Jerry": "Male", "Grace": "Female" } In that example, you reference like People["Jerry"] to see the value "Male". They key to the index is left of the colon. You can also store lists and other data inside the dictionary. I'm not sure where you have questions other than that. Please ask.
21st May 2021, 6:10 PM
Jerry Hobby
Jerry Hobby - avatar
0
Jerry Hobby, I don't understand your MODEL calc section. Please explain more.
31st Mar 2021, 8:28 PM
Ailana
Ailana - avatar
0
Ailana, I gave 3 short steps in my answer which will give the result you need. Are you confused about those too? In case difference is confusing for you, here is more detail: difference = ((total from step 2) - (total from step 1)) "specified age" is int(input()) which you'd store in a variable before the 3 steps begin.
1st Apr 2021, 12:18 AM
Josh Greig
Josh Greig - avatar
0
I don't understand....
1st Apr 2021, 12:33 AM
Ailana
Ailana - avatar
0
Why would the old variable have 530??
1st Apr 2021, 6:23 PM
Ailana
Ailana - avatar
0
Thank you for explaining the 530. Im only 2 or leas months into python and and so far i dislike hard codding anything like that. I rather my program take out human interaction as much as possible.
23rd May 2021, 5:18 PM
Jacque Trahan
Jacque Trahan - avatar
0
How not to hard code 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)
23rd May 2021, 5:26 PM
Jacque Trahan
Jacque Trahan - avatar
0
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)
31st May 2021, 6:07 AM
Anushya Devi T.S PSGRKCW
Anushya Devi T.S PSGRKCW - avatar
0
sigo sin entender los 530
18th Jul 2021, 7:45 AM
Luis Fernández
Luis Fernández - avatar
0
#one solution is like this 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)
26th Apr 2022, 12:27 PM
Muhamed Ademi
Muhamed Ademi - avatar