Created
February 10, 2021 20:54
-
-
Save cbscribe/0e8e487429672beeefb6fc5884136139 to your computer and use it in GitHub Desktop.
Python: validating input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the example we discussed in class. You may find this helpful in your homework assignments (hint, hint).