0

Break and Continue

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 I'm stuck on this program. Kindly assist me if you can

4th Sep 2022, 7:12 PM
Tochukwu Onyebueke
18 Réponses
+ 3
Tochukwu Onyebueke You read the age one time only (int(input()) call) but you have to do 5 times (same time that your while loop is executed then try to move the reading of age inside the while loop.. Pseudo code: For 5 times read the next age as int if the age is more than 2 the total is incremented by 100 after the loop, print the total
4th Sep 2022, 9:31 PM
KrOW
KrOW - avatar
+ 5
Why everyone giving him solution?? Instead of explanation.
6th Sep 2022, 4:10 PM
KARAN SINGH D
KARAN SINGH D - avatar
+ 2
And also hint2: only add 100 to total when age is greater than 2. And hint3: update p-=1 outside if.
4th Sep 2022, 7:44 PM
Jayakrishna 🇮🇳
+ 2
Hi! if this topic is difficult for you, please take the lesson again (which precedes this task) or go back a few steps and start learning all the lesson topics more carefully and diligently again. you were given enough clues, the pseudo code was especially good! 👍😊 Or start learn python from another sources: https://www.w3schools.com/python/python_intro.asp https://www.freecodecamp.org/news/learn-python-free-python-courses-for-beginners/
4th Sep 2022, 10:05 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
KrOW I did it total = 0 x = 0 while x < 5: age =int(input()) if age > 3: total += 100 x += 1 print(total) Thanks
5th Sep 2022, 12:11 AM
Tochukwu Onyebueke
+ 2
🔴Break : break or Stop the loop 🔴Continue : skip the part according to the condition
5th Sep 2022, 6:31 PM
KARAN SINGH D
KARAN SINGH D - avatar
+ 2
I agree with you completely. I dont approve of it either. but how to ban? its impossible
6th Sep 2022, 4:18 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Here's my attempt total = 0 p = 5 age = int(input()) while p > 0: total += 100 if age >2: continue print(total) p -=1
4th Sep 2022, 7:30 PM
Tochukwu Onyebueke
+ 1
Tochukwu Onyebueke You have to read all 5 int (eg. ages) but i see that you read only one of them. Futhermore you have to print the total after processed all ages (hint: input() have to be in loop)
4th Sep 2022, 7:40 PM
KrOW
KrOW - avatar
+ 1
total = 0 i = 5 While i < 5 : age = int(input()) If age < 3: continue Total += 100 print(total)
6th Sep 2022, 3:44 AM
Leovinel
Leovinel - avatar
+ 1
I used this one it works total = 0 passengers = 5 ticket = 100 while passengers > 0: passengers -= 1 age=int(input()) if age<3: continue elif age>2: total += ticket print(total)
6th Sep 2022, 11:56 AM
Amirmahdi
Amirmahdi - avatar
0
KrOW how? I don't get it. I'm so confused right now
4th Sep 2022, 8:54 PM
Tochukwu Onyebueke
0
Maybe try if age is greater than or equal to 3 add 100 to total all in the loop then print total
4th Sep 2022, 9:05 PM
dan
dan - avatar
0
dan an End Of Line Error occurs
4th Sep 2022, 9:18 PM
Tochukwu Onyebueke
5th Sep 2022, 5:14 AM
KrOW
KrOW - avatar
6th Sep 2022, 1:32 PM
yaswanthreddy
0
Js js js
6th Sep 2022, 2:09 PM
yaswanthreddy
0
Come on guys. I'm past that level. Move on!
6th Sep 2022, 10:35 PM
Tochukwu Onyebueke