Skip to content

Instantly share code, notes, and snippets.

@quadrupleslap
Last active February 16, 2017 07:12
Show Gist options
  • Save quadrupleslap/960c33b51de7346a00cb8a86c3a080cf to your computer and use it in GitHub Desktop.
Save quadrupleslap/960c33b51de7346a00cb8a86c3a080cf to your computer and use it in GitHub Desktop.
Simple function to choose from a range of options.
alphabet = "abcdefghijklmnopqrstuvwxyz"
def choose(question, options):
assert 1 < len(options) <= len(alphabet)
while True:
print(question)
for i, opt in enumerate(options):
print("{}) {}".format(alphabet[i], opt))
inp = input("(a-{})> ".format(alphabet[i]))
if len(inp) == 1:
index = alphabet.find(inp)
if -1 < index < len(options):
print("")
return index
print("Invalid input.\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment