Need help with while loops! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Need help with while loops!

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 To solve this do I start with: X = int(input ()) ?

28th Feb 2022, 4:12 PM
pain fr
pain fr - avatar
9 Answers
+ 5
count , sum= 0,0 while count<5: age = input() if age>3: sum+=100 count+=1 print ('Total price is ', sum)
2nd Mar 2022, 1:05 PM
Pythøñ Cúltîst⚔️🔥🇳🇬
Pythøñ  Cúltîst⚔️🔥🇳🇬 - avatar
+ 2
You know exactly how many inputs so you'd take your input in a for loop.
28th Feb 2022, 4:28 PM
Slick
Slick - avatar
+ 2
Your x=int(input()) will work now look at "In range" for python. Id probably start with x=0 x += int(input()) in some type of loop... if the number of inputs is static.
28th Feb 2022, 4:50 PM
William Owens
William Owens - avatar
+ 2
Sum=0 for i in range(5): age=int(input()) if age>3: Sum+=100 print(Sum)
1st Mar 2022, 7:58 PM
Azimjon Abdug'afforov
Azimjon Abdug'afforov - avatar
+ 2
Sum=0 i=0 while i<5: Age=int(input()) if Age>3: Sum+=100 i+=1 print(Sum)
1st Mar 2022, 8:02 PM
Azimjon Abdug'afforov
Azimjon Abdug'afforov - avatar
+ 1
for < 5 times >: age = the input if age is less than 3: free else charge em (add to total)
1st Mar 2022, 1:08 PM
Slick
Slick - avatar
0
Slick could you show me an example please!
1st Mar 2022, 5:31 AM
pain fr
pain fr - avatar
0
Manav Roy I did start python for beginners in solo learn, currently done with 55% of the course can't progress bc I am stuck here.
1st Mar 2022, 6:46 AM
pain fr
pain fr - avatar
0
Manav Roy I asked for help, not whatever this is.
2nd Mar 2022, 2:38 PM
pain fr
pain fr - avatar