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!
2 Respostas
+ 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)
0
Hoh Shen Yien thanks! that wilk work!!