 Ticket prices confusion | SoloLearn: Learn to code for FREE!

0

# Ticket prices confusion

0 is the result from my code. It acts as though it is not continuing with the rest of the code. Any ideas? I looked at the other post, but it does not include continue in the suggested code. total = 0 #your code goes here p = 0 while True: p = p + 1 age = int(input()) if p <= 3: total = 0 continue if p >= 4: total = 100 break print(total)

67 Answers

New Answer

+2

Hi! read the task carefully, the number of passengers is 5. you should take the age of all five of them, compare it, and if it is less than a certain age, you should not take a fee. otherwise, you will sum up the ticket price

+1

are you saying "age" is to go after/under p = p + 1 and "else" should be indented under while? Before you reply, I would like to Thank you for your help.

+1

the while loop - after this line, everything inside it must have at least two indents deep to the right. if you use the if else construction, then they must be on the same line, everything inside them is still indented two spaces to the right

+1

I'm tired, you've tired me.

+1

here is your program, please go through it line by line and find where you were wrong. work on your mistakes

+1

total = 0 - don't write like this. this gives the variable a total value of 0. if you compare, use ==, if you want to add, then total +=0 or total = total + 0

+1

I am studying the codes side by side and see the two differences 1. the location of age = int(input()) 2. the use of += instead of == T H A N K ◇ Y O U Yaroslav! ✔✔✔✔

+1

0

First anomaly I saw in your code was an unused variable "age" But that is irrelevant. I tried running your code and it didnt give any output. I think whats wrong is that you put the continue and break statement inside the if statement so the print statement never gets executed. Because continue statement makes your code go back to rechecking the loop expression and break stops the loop.

0

total = 0 #your code goes here p = 0 while True: p = p + 1 total = total + 100 age = int(input()) if age <= 3: total = 0 continue if age >= 4: total = 100 break if age >= 4: total = 100 break print(total) This gives a result of 100 while solving the second test case. What am I missing that is not adding the 100 to each age over 3?

0

Does the question require you to use break and continue? If not then here is a code that I can suggest : https://code.sololearn.com/cKhKollue5H0/?ref=app If you can add the question details that would be great so I can help in more detail

0

continue and break is the section of python being studied where the question is poised.

0

What am I missing that is causing the code to not add 100 for each age over 3?

0

if you still haven't changed your code and it remains the same, then in the branch operators you don't sum the total ticket price, but in each case you assign the variable total = 100. you must sum 100 + 100, as many times as you have passengers over the age of three years

0

I understand what must be done but do not understand the how and why. My latest attempt has a problem when trying to read age = int (input ())

0

total = 0 #your code goes here p = 0 while True: p = p + 1 age = input() if int(age <= 3: total = 0 continue if int(age) >= 4: total += 100 print(total)

0

Remove break and continue, in while insert condition as long as p is less than 5, add p+1 at the end of the loop. accept the age at the beginning and immediately convert it to an integer, return it as it was

0

The latest incarnation counts each person and adds a 100 for each p even if age is 3 and under. Why is it not looking at the condition that if age is 3 or under the cost is 0? total = 0 #your code goes here p = 0 age = int(input()) while p < 5: p = p + 1 if age >= 4: total += 100 else: if age <= 3: total += 0 print(total)

0

1. Insert "age" into loop (you must take 5 inputs) 2. else must be in a single line column of if

0

read the task condition carefully again and ask yourself the question: why do you use a cycle with 5 repetitions? what's the point?