+ 1

Why won’t this work

I tried making a simple calculator but the indents are acting weird https://code.sololearn.com/cog7gIBHnP2x/?ref=app

23rd Jan 2020, 5:12 PM
Videomaker yt
Videomaker yt - avatar
15 RĂ©ponses
+ 8
In the app, we need to input everything "at once": add 4 5 When asked to input, separate the 3 required inputs by enter
23rd Jan 2020, 5:36 PM
Lisa
Lisa - avatar
+ 7
You forgot to indent one line: b=input(). Also, to make your calculations work, you would also have to make real numbers from your input, for example: b = float(input())
23rd Jan 2020, 5:17 PM
HonFu
HonFu - avatar
+ 3
Indent line 6 (b=...), then the code runs. :) And remember to convert the input numbers to float or int, because by now, your code only pastes the two input numbers together
23rd Jan 2020, 5:21 PM
Lisa
Lisa - avatar
+ 3
Just as Lisa has identified the problem Videomaker yt , in Sololearn, the input has to be inserted all at once. On that topic, here‘s another approach of a very simple calculator: https://code.sololearn.com/cW6rrjRn5b6O/?ref=app
24th Jan 2020, 10:30 AM
aceisace
aceisace - avatar
+ 3
You can enter input in one line by using split function
24th Jan 2020, 7:59 PM
Aman Srivastav
Aman Srivastav - avatar
+ 3
I found another problem in your code. No matter what you write in the first input, the if statement (if a=="add" or "addition" or "+":) will always be true. Solution: if a=="add" or a=="addition" or a=="+":
25th Jan 2020, 10:07 AM
Jannik MĂŒller
Jannik MĂŒller - avatar
+ 2
Just tried your code, works perfectly... Did you run it in the app?
23rd Jan 2020, 5:33 PM
Lisa
Lisa - avatar
+ 2
so just group all the inputs together?
23rd Jan 2020, 5:38 PM
Videomaker yt
Videomaker yt - avatar
+ 2
Yes, each line is for one of the 3 inputs you used (in SL app) When you run it on a your computer, there will be one input window for each
23rd Jan 2020, 5:42 PM
Lisa
Lisa - avatar
+ 2
I think I do not understand your question :) You do not have to group or work around anything, the code runs as it should. At your one computer, python would go through the script line by line and first ask for input a, than b, then c In SL we just cannot go through it "step by step", there will always be this single input window in which we have to input everything and submit.
23rd Jan 2020, 5:59 PM
Lisa
Lisa - avatar
+ 2
I don’t particularly see the error, but instead of print, enter immediately in input. Example: a = float (input ("Enter the first number:")) b = float (input ("Enter the second number: "))
25th Jan 2020, 4:26 PM
Ganji
Ganji - avatar
0
yes
23rd Jan 2020, 5:34 PM
Videomaker yt
Videomaker yt - avatar
0
k well ill try to work arount it
23rd Jan 2020, 5:44 PM
Videomaker yt
Videomaker yt - avatar
0
wait is it the inputs you have to group together or the varibles
23rd Jan 2020, 5:47 PM
Videomaker yt
Videomaker yt - avatar
- 1
that will be a problem in the future
23rd Jan 2020, 5:41 PM
Videomaker yt
Videomaker yt - avatar