Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- def impliesFunc(x,y):
- #if x == y:
- # return True
- #elif y == False:
- # return True
- #else:
- # return False
- if x == False:
- return True
- else:
- return y
- def orFunc(x,y):
- if x==y:
- if x == False:
- return False
- else:
- return True
- else:
- return True
- def andFunc(x,y):
- if x==y:
- if x == True:
- return True
- else:
- return False
- else:
- return False
- def biconditionalFunc(x,y):
- if x == y:
- return True
- else:
- return False
- def negationFunc(x):
- if x == True:
- return False
- else:
- return True
- def truthmaker(d2innit, column):
- dummyarray=[]
- for num in range(32):
- dummyarray.append(d2innit[num][column])
- return dummyarray
- def main():
- # (p implies q) biconditional (r and t) or not s
- toprow = ["p", "q", "r", "s", "t", "expression"]
- #used itertools to create initial truth table
- d2innit = list(itertools.product([False, True], repeat=5))
- #print (d2innit)
- #Assigns columns of the truth table to each variable (plist is column 0, etc)
- pcolumn = truthmaker(d2innit, 0)
- #print(plist)
- qcolumn = truthmaker(d2innit, 1)
- #print(qlist)
- rcolumn = truthmaker(d2innit, 2)
- #print(rlist)
- scolumn = truthmaker(d2innit, 3)
- #print(tlist)
- tcolumn = truthmaker(d2innit, 4)
- #print(slist)
- expressionArray = []
- for num in range(0, 32):
- #goes through proposition starting with paranthesis
- impliesAnswer = impliesFunc(pcolumn[num], qcolumn[num])
- andAnswer = andFunc(rcolumn[num], tcolumn[num])
- bicAnswer = biconditionalFunc(impliesAnswer, andAnswer)
- negAnswer = negationFunc(scolumn[num])
- protoanswer = orFunc(bicAnswer, negAnswer)
- expressionArray.append(protoanswer)
- answerkey = [True,
- True,
- False,
- False,
- True,
- True,
- False,
- True,
- True,
- True,
- False,
- False,
- True,
- True,
- False,
- True,
- False,
- False,
- True,
- True,
- False,
- False,
- True,
- False,
- True,
- True,
- False,
- False,
- True,
- True,#
- False,
- True]
- #compares results to answer key. 1= True, 0=False, X Marks incorrect answers
- for num in range(0, 32):
- print( '{:^3}'.format(num+1), '{:^1}'.format(expressionArray[num]), "-", '{:^1}'.format(answerkey[num]), end=" ")
- if expressionArray[num] != answerkey[num]:
- print (" X ")
- else:
- print()
- main()
Advertisement
Add Comment
Please, Sign In to add comment