Create a file named truthTable.py which contains a function named printTruth Tab
ID: 3869695 • Letter: C
Question
Create a file named truthTable.py which contains a function named printTruth Table printTruth Table will take one argument that is a string def printTruthTable(logicalOperation): You need to create the body of this function so that it will print out the truth table for 1, and when logica!Operation ='and" 2, or when logica!Operation ='or". 3, not when logicalperation == "not". You don't have to do anything fancy to print a truth table. Print statements are OK. Use Python to calculate the "and," or" and "not" operations. You get extra credit if you also make your function handle the special case when the argument sent in is neither 'and' nor 'or' not 'not >>>printTruthTable("and") True and True is True or False, you have Python calculate it here! True and False is True or False. vou have Pvthon calculate it here!Explanation / Answer
##Python v 2.7.13
def printTruthTable(a):
if a=='AND' or a=='and':
print 'true AND true is true'
print 'true AND false is false'
print 'false AND true is false'
print 'false AND false is false'
print
else:
if a=='OR' or a=='or':
print 'true OR true is true'
print 'true OR false is true'
print 'false OR true is true'
print 'false OR false is false'
print
else:
if a=='NOT' or a=='not':
print 'not true is false'
print 'not false is true'
print
else:
if a=='NOR' or a=='nor':
print 'true NOR true is false'
print 'true NOR false is false'
print 'false NOR true is false'
print 'false NOR false is true'
print
else:
if a=='EXOR' or a=='exor':
print 'true EXOR true is false'
print 'true EXOR false is true'
print 'false EXOR true is true'
print 'false EXOR false is false'
print
else:
print a+" is not a legal input!!"
print
printTruthTable('or')
printTruthTable('and')
printTruthTable('not')
printTruthTable('bla bla bla')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.