Commit 284999a9 authored by Gilles Coremans's avatar Gilles Coremans
Browse files

Retry inputs when given bad input

parent a4189354
operand1 = input("First operand: ")
operator = input("Operator: ")
operand2 = input("Second operand: ")
try:
parsed = False
operand1 = input("First operand: ")
while not parsed:
try:
operand1 = int(operand1)
except ValueError:
parsed = True
except ValueError:
print(operand1 + " is not a number!")
exit(1)
operand1 = input("First operand: ")
operator = input("Operator: ")
try:
operand2 = input("Second operand: ")
while not parsed:
try:
operand2 = int(operand2)
except ValueError:
parsed = True
except ValueError:
print(operand2 + " is not a number!")
exit(1)
operand2 = input("Second operand: ")
print("Your result is:")
if operator == "+":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment