Created
July 18, 2014 16:00
-
-
Save micaiahparker/1fe844941fee695d6936 to your computer and use it in GitHub Desktop.
This file contains 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
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