+ 2

Add not defined

num1 =int(input("Enter number 1 /n")) num2 = int(input("Enter number 2")) op = input("Enter operation (add ,sub , mul , div") x = num1 + num2 y= num1 - num2 z = num1 * num2 k = num1 / num2 if op == add: print(x) elif op == (sub): print(y) elif op == (mul): print (z) elif op == (div): print(k) else: print("Error") ....i tried this using the double quotes too

17th Jul 2017, 9:51 AM
Nisan Abeywickrama
Nisan Abeywickrama - avatar
1 Antwort
+ 5
""" You get string from user input, so you need to compare value with string: """ # this 3 first line have some mistakes non blocking (display)... num1 =int(input("Enter number 1 /n")) num2 = int(input("Enter number 2")) op = input("Enter operation (add ,sub , mul , div") x = num1 + num2 y= num1 - num2 z = num1 * num2 k = num1 / num2 if op == "add": print(x) elif op == "sub": print(y) elif op == "mul": print (z) elif op == "div": print(k) else: print("Error")
17th Jul 2017, 11:25 AM
visph
visph - avatar