Question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Question

what is wora at this code? I want to write a programm that take a number from the input an if the input is three or over three take 100$. If the input is under three skip the 100$ this is my code: age = input() total = 0 while age >= 3: total + 100 elif age <= 2: total + 0 print(total)

28th Oct 2021, 6:23 PM
David Berger
4 Answers
+ 2
I added comments in the code. Please put you code on playground so we can test it and indentation doesn't get messed up :) https://code.sololearn.com/cEHxq2i2dAo6/?ref=app
28th Oct 2021, 6:29 PM
Lisa
Lisa - avatar
+ 1
age = input() #here input is of string type so you need convert to needed int type . Like age=int(input()) total = 0 while age >= 3: #here why you need while, you may trying if age>=3: total + 100 #no effect in total because not storing back, you need total= total+100 elif age <= 2: #this elif has useless .. no effect. You can remove. total + 0 print(total) #hope you can correct it now.. edit: corrected code age=int(input()) total = 0 if age>=3: total += 100 print(total)
28th Oct 2021, 6:31 PM
Jayakrishna 🇮🇳
+ 1
Hi David! We can assume that you're trying to take multiple inputs. For that, you have to declare your input variable inside while loop. And, you should declare an increment variable to run the loop. So, your code needs to be like this (Let's say you have to take 5 inputs) total = 0 i = 0 while i <= 4: i += 1 age = int(input()) if age > 3: total += 100 print(total)
29th Oct 2021, 3:38 AM
Python Learner
Python Learner - avatar
0
Age is a string variable, if you want to convert a input in a int result, use "int()", also, the total, you can do total += 100 (a resume of total = total + 100) and, elif is not necessary here, because We don't have a if for starting, and, just erase "total + 0", because he is not going to change the variable, then, erase him and just put the print alone
29th Oct 2021, 1:14 AM
Katdotbrush
Katdotbrush - avatar