i made a simple calulator and im trying to catch an error with the try and except function but its not catching the error for some reason. The error is when i put anything other than a number in the num1 or num2 input. Im receiving a ValueError, but im putting ValueError in the except block and it is still not catching it. I want it to catch the error and print put invalid number instead of actually giving me an error in pycharm.
num1 = float(input("give a number"))
op = input("give an operator")
num2 = float(input("give a number"))
try:
if op == "/":
print(num1/num2)
elif op == "*":
print(num1*num2)
elif op == "-":
print(num1-num2)
elif op == "+":
print(num1+num2)
else:
if op != "/*-+":
print("invalid operator")
except ValueError:
print("invalid number")
this is the error that its giving me
give a number+
Traceback (most recent call last):
File "C:/Users/Kalen/PycharmProjects/m/m.py", line 3, in <module>
num1 = float(input("give a number"))
ValueError: could not convert string to float: '+'