You will write three small functions that build a truth table for any statement. A statement is a Python function such as lambda p, q: p and not q.
The idea. Each simple statement is True or False. With statements there are rows, and itertools.product([True, False], repeat=n) lists them in the usual order.
Your tasks.
rows(n). Return the list of all rows for n statements.column(f, n). Return the list of values of f, one for each row.count_true(f, n). Return how many rows make f true.Run your code once to unlock the worked solution.
Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…