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")
3 Respostas
+ 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.
0
are you sure its "elif"? why don't you try it with " switch" command instead?
0
I haven't learned that yet