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

Retry inputs when given bad input

parent a4189354
parsed = False
operand1 = input("First operand: ") operand1 = input("First operand: ")
operator = input("Operator: ") while not parsed:
operand2 = input("Second operand: ") try:
operand1 = int(operand1)
parsed = True
except ValueError:
print(operand1 + " is not a number!")
operand1 = input("First operand: ")
try: operator = input("Operator: ")
operand1 = int(operand1)
except ValueError:
print(operand1 + " is not a number!")
exit(1)
try: operand2 = input("Second operand: ")
operand2 = int(operand2) while not parsed:
except ValueError: try:
print(operand2 + " is not a number!") operand2 = int(operand2)
exit(1) parsed = True
except ValueError:
print(operand2 + " is not a number!")
operand2 = input("Second operand: ")
print("Your result is:") print("Your result is:")
if operator == "+": 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