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
18 ответов
+ 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
+ 5
Why everyone giving him solution?? Instead of explanation.
+ 2
And also
hint2: only add 100 to total when age is greater than 2.
And hint3: update p-=1 outside if.
+ 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/
+ 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
+ 2
🔴Break : break or Stop the loop
🔴Continue : skip the part according to the condition
+ 2
I agree with you completely. I dont approve of it either. but how to ban? its impossible
+ 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
+ 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)
+ 1
total = 0
i = 5
While i < 5 :
age = int(input())
If age < 3:
continue
Total += 100
print(total)
+ 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)
0
KrOW how? I don't get it. I'm so confused right now
0
Maybe try if age is greater than or equal to 3 add 100 to total all in the loop then print total
0
dan an End Of Line Error occurs
0
Js js js
0
Come on guys. I'm past that level. Move on!