You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lindsay Ward edited this page Aug 17, 2016
·
66 revisions
This page contains standard 'patterns'
Error checking
<priming read - do something the loop depends on>
while <condition based on something from above>:
display error message
<same as the priming read again>
do next thing now that you know the 'something' is valid
valid_input = False
while not valid_input:
try:
age = int(input("Age: "))
valid_input = True
except ValueError: # or just except:
print("Invalid (not an integer)")
print("Next year you will be", age + 1)