0

Need help

What is wrong with this code: Please help check, what is wrong with this code: total = 0 while True: total+=100 age = int(input()) if (age>=3): continue if (age<3): break print(total)

28th Mar 2025, 1:18 PM
Olatunji Oke
8 Answers
+ 3
Olatunji Oke Don't know what the purpose of the code is? But it's working fine without any error, there may be some problem in your input.You input should be a series of numbers and one of them must be lesser than 3 to avoid infinite loop.
28th Mar 2025, 3:10 PM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 2
Olatunji Oke , > can you please post a brief task description? without having seen this, we can not see the issue. i suppose that there may be a logical issue in this code. also share sample input / output if available. > if your post is related to a tutorial / modul / lesson name, please name them. (i remember that there was an exercise like this like ``ticket sale`` or ``ticket price``)
28th Mar 2025, 7:52 PM
Lothar
Lothar - avatar
+ 2
Thanks everyone, all your suggestions were very helpful. I was trying to run the code in sololearn playground, the code run perfectly on Spyder. Thanks once again
30th Mar 2025, 1:03 AM
Olatunji Oke
+ 2
Olatunji Oke , now i found the task description for this exercise: > 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 > Program needs to take the ages of 5 passengers as input and output the total price for their tickets your code may run without raising an issue. > but using the above description for the calculation, the result will not be as expected. the logic seems not following the description. > when using these inputs: 1, 25, 2, 1, 16, the program *terminates* the execution just after the *first* input (because the while loop will be terminated by a *break* statement) and the result shows 100, but should be 200.
30th Mar 2025, 8:01 AM
Lothar
Lothar - avatar
+ 1
So Lothar, what should have been the correct code for this program or what can be done to fix the concerns you raised.
30th Mar 2025, 9:49 PM
Olatunji Oke
+ 1
Olatunji Oke , it is seen as not very helpful to share ready-made codes. you can do a new try and share it here, if you think it needs some improvement.
31st Mar 2025, 8:52 AM
Lothar
Lothar - avatar
0
Olatunji Oke If you are trying to run that inside the SoloLearn Code Playground, the problem might not be with you, but with SoloLearn. SoloLearn Code Playground wants to read in ALL necessary input at once in 1 input request. So it is not good for testing inputs within loops with unknown length. You might want to download a Python IDE which includes compiler to your own computer.
28th Mar 2025, 7:11 PM
Shardis Wolfe
0
Olatunji Oke as a hint, you know how many inputs will be provided. So remember which type of loop is preferred when number of repetitions is already known. This exercise can be solved within SoloLearn Playground.
1st Apr 2025, 2:30 AM
Shardis Wolfe