I was told to write a code that print the cost for everyone who's age started from four to above while ages three to below output nothing. I coded this but Sololearn still didn't accept it, but I tested my code on an IDE called Replit and it worked as mentioned as my task at Sololearn. can someone tell me why Sololearn won't accept it? My code below: Cost = 0 while 0 < 5: age = int(input()) if age > 3: Cost += 100 print(Cost)
3/11/2022 2:42:37 PM
George A.11 Answers
New AnswerYou have created an infinite loop, it's like writing: "while True:" Read the while loop lesson carefully. Also, the output of the result should be once.
You enter data five times, and your code asks for data input an infinite number of times without receiving values.
I mean like this: Cost = 0 n = 0 while n < 5: age = int(input()) if age > 3: Cost += 100 n += 1 print(Cost)
Do you mean like this?: Cost = 0 n = 0 while n < 5: age = int(input()) if age > 3: Cost += 100 n += 1 print(Cost)
in your line2,it is the same “while False”,it means all code which under the while will not work,so you need to change the condition of while.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message