0

Need help

You are making a ticketing system. The price of a single ticket is $100. For children under 3 years of age, 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

9th Jan 2022, 2:53 PM
Williams Dezano
Williams Dezano - avatar
7 ответов
+ 4
You can't stop an infinite loop(while True) unless you're using a break statement. You can try this instead total = 0 i = 0 #your code goes here while i <5: age = int(input()) if age >= 4: total += 100 i += 1 print(total)
9th Jan 2022, 4:42 PM
Simba
Simba - avatar
+ 1
Hello . Please first show your attempt
9th Jan 2022, 3:10 PM
MATOVU CALEB
MATOVU CALEB - avatar
0
total = 0 #your code goes here while True: age = int(input()) if age >= 4: total+= 100 print(total) continue
9th Jan 2022, 3:13 PM
Williams Dezano
Williams Dezano - avatar
0
Hey, get the input into a list, and loop through that list, checking if each age is greater or equal to 3, and if it is, you sum 100 to the total price, like ... ages = [18, 24, 2, 5, 42] totalToPay =0 for age in ages: if age >= 3: totalToPay += 100 print(totalToPay)
9th Jan 2022, 3:20 PM
Gabriel Wiedemann
Gabriel Wiedemann - avatar
0
age depends on user input
9th Jan 2022, 3:46 PM
Williams Dezano
Williams Dezano - avatar
0
So if you enter the age as an array at once, then: age = list(input()) If you enter ages one by one, like 5 individual entries, then: ages = [] For i in range(5) ages.append(int(input())) There is a lot ways of doing that, if none of these is you case, then how is it asked to enter the ages?
9th Jan 2022, 3:58 PM
Gabriel Wiedemann
Gabriel Wiedemann - avatar
0
total = 0 #your code goes here #age = int(input()) for i in range(5): age = int(input()) if age >= 3: total+= 100 if age <= 2: continue print(total) Thanks all
9th Jan 2022, 4:50 PM
Williams Dezano
Williams Dezano - avatar