Aug-26-2019, 04:34 PM
(This post was last modified: Aug-26-2019, 04:54 PM by ichabod801.)
I am working on some basic programming homework, a calculator. The code is below.
I would like for the user to be able to input / or \ for division. However, the code below does not work. If I remove the or "\\", the program runs fine. Any guidance is appreciated!
I would like for the user to be able to input / or \ for division. However, the code below does not work. If I remove the or "\\", the program runs fine. Any guidance is appreciated!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
print ( "Acceptable operators include *, /, \, +, -" ) math_num1 = input ( "Please enter the first number: " ) math_oper = input ( "Please enter the operator: " ) math_num2 = input ( "Please enter the second number: " ) if math_oper = = "*" : print ( int (math_num1) * int (math_num2)) elif math_oper = = "/" or "\\" : print ( int (math_num1) / int (math_num2)) elif math_oper = = "+" : print ( int (math_num1) + int (math_num2)) elif math_oper = = "-" : print ( int (math_num1) - int (math_num2)) else : print ( "Invalid Input! Please try again." ) |