Skip to content

Instantly share code, notes, and snippets.

@Telltak
Created November 18, 2010 19:47
Show Gist options
  • Save Telltak/705491 to your computer and use it in GitHub Desktop.
Save Telltak/705491 to your computer and use it in GitHub Desktop.
Based on exercise 27 of lpthw, gives a statement and user must answer true or false.
import random
statement_answer_pairs = {'not False ':'true', 'not true ':'false',
'True or False ':'true', 'True or True ':'true',
'False or True ':'true', 'False or False ':'false',
'True and False ':'false', 'True and True ':'true',
'False and True ':'false', 'False and False ':'false',
'not (True or False) ':'false', 'not (True or True) ':'false',
'not (False or True) ':'false', 'not (False or False) ':'true',
'not (True and False) ':'true', 'not (True and True) ':'false',
'not (False and True) ':'true', 'not (False and False) ':'true',
'1 != 0 ':'true', '1 != 1 ':'false', '0 != 1 ':'true',
'0 != 0 ': 'false', '1 == 0 ':'false', '1 == 1 ':'true',
'0 == 1 ':'false', '0 == 0 ':'true'}
for i in range(0, 10):
item = random.randint(0, len(statement_answer_pairs))
answer = raw_input(statement_answer_pairs.keys()[item-1])
if answer == statement_answer_pairs.values()[item-1]:
print "well done!"
else:
print "Sorry, it was %r" % statement_answer_pairs.values()[item-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment