Skip to content

Instantly share code, notes, and snippets.

@QuanSai
Created September 3, 2012 07:16
Show Gist options
  • Save QuanSai/3607528 to your computer and use it in GitHub Desktop.
Save QuanSai/3607528 to your computer and use it in GitHub Desktop.
Truth Table Tester - Asks the user a truth table-related question; Spits out correct answer if the answer provided is wrong.
'''
Created on Sep 03, 2012
@author: Gregory A. Thompson Jr.
Truth Table Tester
booltest.py
-Asks the user a truth table-related question.
-Spits out correct answer if the answer provided is wrong.
'''
import random as ran
if __name__ == '__main__':
values = ['True', 'False']
operators = ['and', 'or']
while(True):
statement = ran.choice(values) + " " + ran.choice(operators) + " " + ran.choice(values)
nots = "not('" + statement + "')"
question = ran.choice([statement, nots])
answer = eval(question)
usr_in = raw_input("The statement \"" + question + "\" is ")
if usr_in != str(answer):
print "Wrong!\a"
print "It was actually " + str(answer) + "."
else:
print "That's correct!"
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment