Skip to content

Instantly share code, notes, and snippets.

@micaiahparker
Created July 18, 2014 16:00
Show Gist options
  • Save micaiahparker/1fe844941fee695d6936 to your computer and use it in GitHub Desktop.
Save micaiahparker/1fe844941fee695d6936 to your computer and use it in GitHub Desktop.
from os import name, system
def question(prompt, type_, predicate=None):
while True:
answer = input(prompt)
try:
thing = type_(answer)
if predicate is None or predicate(thing):
return thing
else:
print('invalid:', thing)
except ValueError:
print('unable to convert {!r} to {}'.format(answer, type_))
def clear():
if name = 'nt':
system('cls')
else:
system('clear')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment