Created
January 25, 2014 23:44
-
-
Save hexsprite/8625585 to your computer and use it in GitHub Desktop.
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
| def choose_from(choices, prompt="Which do you choose?"): | |
| while True: | |
| for index, choice in enumerate(choices): | |
| print "%2d. %s" % (index, choice) | |
| choice = raw_input("\n%s " % prompt) | |
| try: | |
| choice = int(choice) | |
| if choice < 0: | |
| raise ValueError | |
| return choices[choice] | |
| except (ValueError, IndexError): | |
| print "Invalid choice" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment