""" Show explicitly that de Morgan's Laws are correct. Oct 14 homework sol'n by Jim M. See http://en.wikipedia.org/wiki/De_Morgan_duality """ print "truth tables for de Morgan's Laws" print morgans_laws = [ ["not (P and Q)", "(not P) or (not Q)"], ["not (P or Q)", "(not P) and (not Q)"] ] template = " {:8} {:8} {:20} {:20} {:6} " for statements in morgans_laws: left_string = statements[0] right_string = statements[1] print template.format('P', 'Q', left_string, right_string, 'same') print template.format('-'*8, '-'*8, '-'*20, '-'*20, '-'*6) for P in (True, False): for Q in (True, False): left = eval(left_string) right = eval(right_string) if left == right: same = 'yes' else: same = 'no' print template.format(P, Q, left, right, same) print