names = "false nor xleft nleft xright nright xor nand and nxor right nxright left nxleft or true".split() lookup = dict(map(reversed, enumerate(names))) prompt = "<logic gate> <operator> <logic gate>: " print while 1: try: tables = table1, table2, table3 = raw_input(prompt).lower().split() rtable1, rtable2, rtable3 = map(lookup.get, tables) except: raise SystemExit r = sum((x*(bool(rtable2 & (1<<(3-((bool(rtable1 & x) * 2) + bool(rtable3 & x)))))) for x in [1, 2, 4, 8])) print '%s %s %s == %s' % (table1.capitalize(), table2, table3.capitalize(), names[r].capitalize())
just an experiment i wanted to try where you can do a logical operation on two truth tables and get a truth table back.
there are 16 truth tables and 16 operations, giving 4096 possible inputs and 16 possible outputs.
ex:
<logic gate> <operator> <logic gate>: and xor or
And xor Or == Xor
i also have a whole separate module just for helping to custom-make a set of names to use for the 16 truth tables by passing parameters, but it's not finished yet.