+ 1
Python For Beginners
I've been trying for so long to get this right and I just don't understand how this is wrong. Question: continue You are making a ticketing system. The price of a single ticket is $100. For children under 3 years old, the ticket is free. Your program needs to take the ages of 5 passengers as input and output the total price for their tickets. Sample Input 18 24 2 5 42 Sample Output 400 My Code: total = 0 #your code goes here p = 0 ages = int(input()) while p<5: total=total+100 p=p+1 if ages <=3: total=total-100 continue print(total)
3 ответов
+ 2
Currently your code only takes input once. However you need to take input 5 times, so input would should be inside the loop. The "continue" can be removed
+ 2
0
I recommend using lists to save the ages
total = 0
#your code goes here
ages = []
while len(ages)<5:
age=int(input())
if(age>3):
total += 100
ages.append(age)
print(total)