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. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

https://code.sololearn.com/cICT9CdwlCUA/?ref=app

31st Aug 2019, 7:20 AM
Mohammed Al-Mhanna
Mohammed Al-Mhanna - avatar
15 Answers
+ 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)
31st Aug 2019, 8:00 AM
Sousou
Sousou - avatar
+ 1
str(a+d) try that, I've not got my pc on to use my IDE.
31st Aug 2019, 7:36 AM
rodwynnejones
rodwynnejones - avatar
+ 1
you have a small indent jut before the print statement, just remove it.
31st Aug 2019, 7:43 AM
rodwynnejones
rodwynnejones - avatar
+ 1
your if statement in wrong, test the input against all the options eg if x== a or x == b or x==c....etc
31st Aug 2019, 7:50 AM
rodwynnejones
rodwynnejones - avatar
+ 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.
31st Aug 2019, 7:57 AM
rodwynnejones
rodwynnejones - avatar
+ 1
Sousou Thank you! It works!
31st Aug 2019, 8:03 AM
Mohammed Al-Mhanna
Mohammed Al-Mhanna - avatar
0
put in input function in an int function eg x = int(input("blah blah blah"))
31st Aug 2019, 7:31 AM
rodwynnejones
rodwynnejones - avatar
0
rodwynnejones Thank you! But I am having a syntax error on line 5. Do you know how to fix that?
31st Aug 2019, 7:33 AM
Mohammed Al-Mhanna
Mohammed Al-Mhanna - avatar
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.
31st Aug 2019, 7:40 AM
Mohammed Al-Mhanna
Mohammed Al-Mhanna - avatar
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.
31st Aug 2019, 7:45 AM
Mohammed Al-Mhanna
Mohammed Al-Mhanna - avatar
0
rodwynnejones Sorry, but it seems that I don't understand what you are trying to say.
31st Aug 2019, 7:51 AM
Mohammed Al-Mhanna
Mohammed Al-Mhanna - avatar
0
rodwynnejones Oh I see, thank you! Tho line 5 still doesn't work 😅
31st Aug 2019, 7:58 AM
Mohammed Al-Mhanna
Mohammed Al-Mhanna - avatar
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!
31st Aug 2019, 8:07 AM
Mohammed Al-Mhanna
Mohammed Al-Mhanna - avatar
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))
31st Aug 2019, 10:34 AM
rodwynnejones
rodwynnejones - avatar
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 ())"
31st Aug 2019, 10:42 AM
Mohammed Al-Mhanna
Mohammed Al-Mhanna - avatar