Guest User

Untitled

a guest
Jan 29th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. import itertools
  2.  
  3. def impliesFunc(x,y):
  4. #if x == y:
  5. # return True
  6. #elif y == False:
  7. # return True
  8. #else:
  9. # return False
  10. if x == False:
  11. return True
  12. else:
  13. return y
  14.  
  15. def orFunc(x,y):
  16. if x==y:
  17. if x == False:
  18. return False
  19. else:
  20. return True
  21. else:
  22. return True
  23.  
  24. def andFunc(x,y):
  25. if x==y:
  26. if x == True:
  27. return True
  28. else:
  29. return False
  30. else:
  31. return False
  32.  
  33. def biconditionalFunc(x,y):
  34. if x == y:
  35. return True
  36. else:
  37. return False
  38.  
  39. def negationFunc(x):
  40. if x == True:
  41. return False
  42. else:
  43. return True
  44.  
  45. def truthmaker(d2innit, column):
  46. dummyarray=[]
  47. for num in range(32):
  48. dummyarray.append(d2innit[num][column])
  49. return dummyarray
  50.  
  51. def main():
  52. # (p implies q) biconditional (r and t) or not s
  53. toprow = ["p", "q", "r", "s", "t", "expression"]
  54.  
  55. #used itertools to create initial truth table
  56. d2innit = list(itertools.product([False, True], repeat=5))
  57. #print (d2innit)
  58.  
  59. #Assigns columns of the truth table to each variable (plist is column 0, etc)
  60. pcolumn = truthmaker(d2innit, 0)
  61. #print(plist)
  62. qcolumn = truthmaker(d2innit, 1)
  63. #print(qlist)
  64. rcolumn = truthmaker(d2innit, 2)
  65. #print(rlist)
  66. scolumn = truthmaker(d2innit, 3)
  67. #print(tlist)
  68. tcolumn = truthmaker(d2innit, 4)
  69. #print(slist)
  70.  
  71. expressionArray = []
  72.  
  73. for num in range(0, 32):
  74.  
  75. #goes through proposition starting with paranthesis
  76. impliesAnswer = impliesFunc(pcolumn[num], qcolumn[num])
  77. andAnswer = andFunc(rcolumn[num], tcolumn[num])
  78. bicAnswer = biconditionalFunc(impliesAnswer, andAnswer)
  79. negAnswer = negationFunc(scolumn[num])
  80. protoanswer = orFunc(bicAnswer, negAnswer)
  81. expressionArray.append(protoanswer)
  82.  
  83. answerkey = [True,
  84. True,
  85. False,
  86. False,
  87. True,
  88. True,
  89. False,
  90. True,
  91. True,
  92. True,
  93. False,
  94. False,
  95. True,
  96. True,
  97. False,
  98. True,
  99. False,
  100. False,
  101. True,
  102. True,
  103. False,
  104. False,
  105. True,
  106. False,
  107. True,
  108. True,
  109. False,
  110. False,
  111. True,
  112. True,#
  113. False,
  114. True]
  115.  
  116. #compares results to answer key. 1= True, 0=False, X Marks incorrect answers
  117. for num in range(0, 32):
  118.  
  119. print( '{:^3}'.format(num+1), '{:^1}'.format(expressionArray[num]), "-", '{:^1}'.format(answerkey[num]), end=" ")
  120. if expressionArray[num] != answerkey[num]:
  121. print (" X ")
  122. else:
  123. print()
  124. main()
Advertisement
Add Comment
Please, Sign In to add comment