0

Why is my code not working, please help.

I entered this code into Sololearn's code playground and it worked but it didn't in python shell. this was the code: n1 = input("Enter the first number: ") print(n1) op = input("Enter the opperation: ") print(op) n2 = input("Enter the second number: ") print(n2) if op == str("+"): print(int(n1) + int(n2)) elif op == str("-"): print(int(n1) - int(n2)) elif op == str("*"): print(int(n1) * int(n2)) elif op == str("/"): print(int(n1) / int(n2)) else: print("only enter the common 4 types of opperatiors")

19th Nov 2017, 11:08 PM
Christian Dooley
Christian Dooley - avatar
3 Respuestas
+ 3
By Python shell I think you mean the interactive mode (with the >>> prompt). The empty lines between your "if" statements and the subsequent "elif" cause the interactive interpreter to close the "if" context (making "elif" a surprise syntax error). Remove the empty lines. This is not a problem for scripts, just interactive mode.
19th Nov 2017, 11:49 PM
Kirk Schafer
Kirk Schafer - avatar
0
are you sure its "elif"? why don't you try it with " switch" command instead?
19th Nov 2017, 11:14 PM
Dmitrii
Dmitrii - avatar
0
I haven't learned that yet
19th Nov 2017, 11:18 PM
Christian Dooley
Christian Dooley - avatar