Skip to content

Instantly share code, notes, and snippets.

@cbscribe
Created February 10, 2021 20:54
Show Gist options
  • Save cbscribe/0e8e487429672beeefb6fc5884136139 to your computer and use it in GitHub Desktop.
Save cbscribe/0e8e487429672beeefb6fc5884136139 to your computer and use it in GitHub Desktop.
Python: validating input
# Validating input
while True:
try:
num = int(input("Pick a number from 1 to 10: "))
except ValueError:
continue
if num >= 1 and num <= 10:
break
@cbscribe
Copy link
Author

This is the example we discussed in class. You may find this helpful in your homework assignments (hint, hint).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment