+ 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)

13th Nov 2021, 10:19 PM
Kianna Hendricks
Kianna Hendricks - avatar
3 odpowiedzi
+ 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
13th Nov 2021, 10:52 PM
Lisa
Lisa - avatar
14th Nov 2021, 2:10 AM
Krishnam Raju M
Krishnam Raju M - avatar
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)
14th Nov 2021, 12:48 AM
Jairo Soto
Jairo Soto - avatar