Ticket price sum | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Ticket price sum

To calculate the sum of tickets that each cost 100 dollars we needed a code that only sums price for 5 passengers. And then only if they are 3 years or older. Why does the age=int(input)) have to go after the while loop and cannot be defined before it (e.g. in line 3)? Below the correct code. total = 0 x = 0 while x<5: x+=1 age=int(input()) if age <3: continue else: total += 100 print(total)

20th Nov 2022, 2:36 AM
SAH
SAH - avatar
2 Answers
+ 2
Everything inside the loop is done multiple times. If you put the input() before the loop, it will be run only once, but you need to ask 5 numbers, that's why it's inside.
20th Nov 2022, 5:56 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Thank you!!
20th Nov 2022, 6:25 AM
SAH
SAH - avatar