+ 2

# Need help on Ticketing System. Anyone?

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. What I am writing is: total = 0 passengers = 0 while passengers <=5: age = int(input()) if (age == 3): continue total += 100 passengers += 1 print (total) Error I am getting is EOF error in line 4. What’s that? And are the other statements correct?

29th Oct 2021, 1:00 PM
Abhinay Kumar Singh
4 Réponses
+ 4
you put the total and passengers vars within the if-statement so it takes more than 5 passengers which is not correct. here is my code total = 0 passengers = 0 while passengers < 5: age = int(input('enter age: ')) passengers += 1 if age <= 3: continue total += 100 print(total)
29th Oct 2021, 1:38 PM
Krishnam Raju M
+ 3
Code's fine. But when you start at an index of 0 and go until you are past 5, that's 6 values and it only is giving 5. So it hangs on that last iteration when it tries to grab input while passengers < 5:
29th Oct 2021, 1:13 PM
Slick
0
Krishnam Raju M Ohh alright. The system has to count the passenger even if s/he is less than 3 years old, just need not add the amount. Now it worked, after also correcting the age condition!! thanks buddy 😃
29th Oct 2021, 1:54 PM
Abhinay Kumar Singh
0
Slick : got it now.. thanks 😃
29th Oct 2021, 1:57 PM
Abhinay Kumar Singh
Aujourd'hui en vedette
PRO vs MAX