Asked • 06/23/19

python build a dynamic growing truth table?

My question is simple: "how to build a dynamic growing truth table in python in an elegant way?" for n=3 for p in False, True: for q in False, True: for r in False, True: print '|{0} | {1} | {2} |'.format(int(p),int(q), int(r)) for n=4 for p in False, True: for q in False, True: for r in False, True: for s in False, True: print '|{0} | {1} | {2} | {3}'.format(int(p),int(q), int(r), int(s)) I would like to have a function which takes n as a parameter and builds up the table, it is not necessary to print the table, returning a data structure representing the table is fine also.

1 Expert Answer

By:

Andrew J. answered • 07/11/19

Tutor
5 (1)

Professional Software Developer with Python Experience

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.