0
I am new to Python and I decided to make a calculator, but now I am stuck with a syntax error. I appreciate any kind of advice.
15 Réponses
+ 1
a = input("Please enter a simple way of calculation \n")
if (a == "Addition" or a=="addition" or a=="Plus" or a=="plus" or a=="Add" or a=="add"):
b = int(input("Please enter your first integer \n"))
c = int(input("Please enter your second integer \n"))
print("The answer is",b+c)
+ 1
str(a+d) try that, I've not got my pc on to use my IDE.
+ 1
you have a small indent jut before the print statement, just remove it.
+ 1
your if statement in wrong, test the input against all the options eg
if x== a or x == b or x==c....etc
+ 1
if a == "Addition" or a== "addition" or a == "Plus" or a == "plus" or a == "Add" or a == "add"):
I would of used 'in' in this situation.
+ 1
Sousou Thank you! It works!
0
put in input function in an int function eg x = int(input("blah blah blah"))
0
rodwynnejones Thank you! But I am having a syntax error on line 5. Do you know how to fix that?
0
rodwynnejones That is a good advice for the last part of line five, but I tried removing it and leaving
"print("The answer is")"
But even when I do that it shows a syntax error 🤔
It seems there is a problem with the print function.
0
rodwynnejones Sorry for all the trouble I've made for you, but even after I removed the indent there still seems to be a syntax error. You don't have to continue helping me if you don't want to.
Thank you.
0
rodwynnejones Sorry, but it seems that I don't understand what you are trying to say.
0
rodwynnejones Oh I see, thank you! Tho line 5 still doesn't work 😅
0
rodwynnejones Didn't notice it lol, thank you. Sousou Fixed my code a little bit earlier, but you still provided valuable advice and fixed my code, so thank you too!
0
Just looked at your amended code and ....there's no reason to assign 'a' to the other variables, just us 'a' again in the elif statement.
also...just a little more info... you can;-
print("The answer is " + str(a+b))
0
rodwynnejones Changed it and I also changed my calculator so that it can support floats by replacing "x = int (input ())" to
"x = float (input ())"