+ 1

NEED HELP SOLVING THIS QUESTION

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 try, result is 100 https://code.sololearn.com/ccwZCY4QFqp1 age = int(input()) passenger = 5 total = 100 while passenger < 5: if age <=3: continue total + 100 print (total) SOLUTION total = 0 #your code goes here def passenger_ticket(): p_ages = [] age1 = int(input()) age2 = int(input()) age3 = int(input()) age4 = int(input()) age5 = int(input()) p_ages.append(age1) p_ages.append(age2) p_ages.append(age3) p_ages.append(age4) p_ages.append(age5) price = 100 total = 0 for age in p_ages: if age >= 3: total += price print(str(total)) passenger_ticket()

4th Jan 2022, 6:06 PM
David Peterside
5 odpowiedzi
+ 3
1. You have to input age for each passenger. So, this input must be inside the loop. 2. You initialize total with 100 - which is the correct total *before* adding the price for each passenger? 3. Your loop starts with passenger = 5, and tests id passenger < 5. So, it will never run. Hint: what about a for loop instead? Plus: read about "_" variable. 4. "total + 100" doesn't change total. Review the lessons on assignment operators. Hint: "+" isn't an assignment operator, but it's quite close. 5. "total + 100" is after "continue", do will never execute. Hint: instead of skipping for ages up to 3, why don't just run for ages above 3?
4th Jan 2022, 7:26 PM
Emerson Prado
Emerson Prado - avatar
+ 3
Another point: link your code from code playground in the question itself (edit it), using + button. This helps a lot those who wanna help. Just get used to do it this way, and you'll get better and faster help.
4th Jan 2022, 7:28 PM
Emerson Prado
Emerson Prado - avatar
+ 2
Please attach your attempt first, otherwise, we cannot help you
4th Jan 2022, 6:09 PM
CGM
CGM - avatar
0
my try, result is 100 @emerson prado age = int(input()) passenger = 5 total = 100 while passenger < 5: if age <=3: continue total + 100 print (total)
4th Jan 2022, 6:54 PM
David Peterside
10th Jan 2022, 11:32 AM
David Peterside