I am trying to write an error handler,
so something like this example:
time = int(input"Is the number greater (>), lesser (<) or equal (=)? "))
except ValueError
print ("Incorrect Input!")
However, I want the user to input a symbol, does anyone know if there is anything I can use instead of int for this?
Many thanks in advance :)
CodePudding user response:
There isn't an operator type in Python, so you would have to keep them as a string and then check if the input is one of those three, and then determine which one it is and respond accordingly.
while True:
op = input("Is the number greater (>), lesser (<) or equal (=)? ")
if op == '>':
# Operator is >
break;
elif op == '<':
# Operator is <
break;
elif op == '=':
# Operator is ==
break;
else:
print("Invalid operator. Please try again. ")
# use operator