Just like how num1
will only except an integer, I want op
to only except the symbols "/*-+" and if the person inputs something otherwise I can then throw up an "invalid operator" message right after they input something other than those 4 symbols.
try:
num1 = float(input("enter a number"))
op = input(("enter a operator"))
num2 = float(input("enter another number"))
if op == "+":
print(num1 + num2)
elif op == "-":
print(num1 - num2)
elif op == "*":
print(num1 * num2)
elif op == "/":
print(num1 / num2)
except ValueError:
print("invalid operator")
except:
print("invalid")