Need help with ticket calculator | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Need help with ticket calculator

At a park, if a kid is 5 or older, pays $100 for entrance. If he’s younger, he pays $0 If I input different ages, I beet a program that calculates the total entrance fee. Sample input: 18 12 10 3 7 Sample output: 400 This is my code and I don’t know what I’m missing: total = 0 age = input() while True: if int (age) < 5: ticket = 0 else: ticket = 100 total += ticket print (total) Please help!

21st Feb 2021, 12:36 AM
Daniel Lopez
2 Antworten
+ 2
The problem is with your while True, it'll go indefinitely making it an infinite loop. So if the program always accepts 5 ages, then maybe you can do like this total = 0 # you can use while loop too if you want for i in range(5): age = int(input) if age >= 5: total += 100 #can straight away add in, no need hold it, somewhere else print(total)
21st Feb 2021, 1:28 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
0
Hoh Shen Yien thanks! that wilk work!!
21st Feb 2021, 2:08 AM
Daniel Lopez