Question: import itertools, inspect def nparams(f): return len(inspect.signature(f).parameters) def TruthTable(f): n = nparams(f) for j in range(n): print ( {0:6s}.format(chr(65+j)), end=) print(| f +6 *n*-+------) alltuples


import itertools, inspect
def nparams(f): return len(inspect.signature(f).parameters)
def TruthTable(f): n = nparams(f) for j in range(n): print (" {0:6s}".format(chr(65+j)), end="")
print("| f "+6 *n*"-"+"------")
alltuples = itertools.product([True,False], repeat=n) for combination in alltuples: for value in combination: print("{0:6s}".format(str(value)), end="") result = f(*combination) print("| {0:6s}".format(str(result)))
def f(P,Q,R,S): return ((P and Q) and (P or S or Q) and (P or R))
TruthTable(f)
Modify TruthTable (f) to print one letter T or F instead of the en- tire string True or False. Python does not have a built in implementation for A = B. Im- plement a function ifthen (A,B) that returns the value of A B. Then use TruthTable to print the truth tables of the following: a) ( PQ) ^ (QP) b) (P ^Q) = (R v (Q ^ S))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
