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
7 Answers
+ 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)
+ 1
Hello . Please first show your attempt
0
total = 0
#your code goes here
while True:
age = int(input())
if age >= 4:
total+= 100
print(total)
continue
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)
0
age depends on user input
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?
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