0

Ticket office project

Here is the code I produced, is there any way I could’ve made it simpler ? Thank you In advance! https://code.sololearn.com/chDskE8Acu3u/?ref=app

5th Jul 2022, 4:59 AM
Ishaaq Aba Bagnan
5 RĂ©ponses
+ 1
Hi! I can’t see how you are using the dictionary ’data’. Hiw do you want you to use the information in ’data’?
5th Jul 2022, 6:15 AM
Per Bratthammar
Per Bratthammar - avatar
0
Hey! The task gave me a tip that said: « To iterate over the values of a dictionary, you can use the .values() function: for value in data.values(). » I did not understant that so I proceeded to manually write the values from data that I needed. Thsi program was to compare the age of a ticket buyer, assign it an amount paid , and add up all of these values. And finally assess what would be the % of profit if the age for discount was changed.
5th Jul 2022, 6:22 AM
Ishaaq Aba Bagnan
0
Hi! Yes its correct. You can iterate over the values in ’data’: for i in data.values(): do_this(i) if i == input_value: do_that() 
 where do_this is some kind of code. So the keys in data is som kind of id-number?
5th Jul 2022, 6:31 AM
Per Bratthammar
Per Bratthammar - avatar
0
The keys in data are for the ticket number indeed
5th Jul 2022, 6:33 AM
Ishaaq Aba Bagnan
0
# Here's a variant of your code with the reapeting parts in a # function and using the info in your 'data' dict. # N.B. The dictionary ’data’ is not included in the code below # (because its relative big, but you can test the code by follow the in the link). def income(yr): res = 0 for i in data.values(): res += 5 if i < yr else 20 return res age = int(input()) old, new = income(18), income(age) growth = ((new - old) / old) * 100 print(round(growth, 2)) https://code.sololearn.com/c4wxXRP2WP18/?ref=app
5th Jul 2022, 7:46 AM
Per Bratthammar
Per Bratthammar - avatar