Skip to content

Instantly share code, notes, and snippets.

@jbarratt
Last active August 29, 2015 13:58
Show Gist options
  • Save jbarratt/10071250 to your computer and use it in GitHub Desktop.
Save jbarratt/10071250 to your computer and use it in GitHub Desktop.
Simple input grabbing
#!/usr/bin/env python
def get_yn(question):
prompt = question + " [y/n]: "
ok = {'y', 'n'}
answer = None
while answer not in ok:
answer = raw_input(prompt).strip().lower()
return answer == 'y'
def main():
if get_yn("My question?"):
print "Yes"
else:
print "Noooooo!"
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment