Give Python code to print an address such as "851 S. Morgan, IL 60607" using the information in the dictionary.
Answer:
>>> D = {'street':'S. Morgan', 'number':851, 'state':'IL', 'zip':60607}
>>> s = str(D['number']) + ' ' + D['street'] + ', ' + D['state'] + ' ' + str(D['zip'])
>>> print s
851 S. Morgan, IL 60607
(x and not y and z) or (not x and y and not z).Write the truth table for this expression below.
Answer:
using Sage:
sage: logic = SymbolicLogic()
sage: s = logic.statement("(x & !y & z)|(!x & y & !z)")
sage: t = logic.truthtable(s)
sage: logic.print_table(t)
x | y | z | value |
--------------------------------
False | False | False | False |
False | False | True | False |
False | True | False | True |
False | True | True | False |
True | False | False | False |
True | False | True | True |
True | True | False | False |
True | True | True | False |