boolean - Creating a truth table for any expression in Python -


i attempting create program when run ask boolean expression, variables , create truth table whatever entered. need use class , have far. not sure go here.

from itertools import product  class boolean(object):         def __init__(self, statement, vars):            self.exp = statement            self.vars = vars         def __call__(self, statement, vars):  def main():    expression = raw_input('give expression:')    vars = raw_input('give names of variables:')    variables = vars.split(' ')    b = boolean(expression, variables)  if __name__ == "__main__":    main() 

i have library want! check out github repo or find here on pypi.

the readme describes how works, here's quick example:

from truths import truths print truths(['a', 'b', 'x', 'd'], ['(a , b)', 'a , b or x', 'a , (b or x) or d']) +---+---+---+---+-----------+--------------+---------------------+ | | b | x | d | (a , b) | , b or x | , (b or x) or d | +---+---+---+---+-----------+--------------+---------------------+ | 0 | 0 | 0 | 0 |     0     |      0       |          0          | | 0 | 0 | 0 | 1 |     0     |      0       |          1          | | 0 | 0 | 1 | 0 |     0     |      1       |          0          | | 0 | 0 | 1 | 1 |     0     |      1       |          1          | | 0 | 1 | 0 | 0 |     0     |      0       |          0          | | 0 | 1 | 0 | 1 |     0     |      0       |          1          | | 0 | 1 | 1 | 0 |     0     |      1       |          0          | | 0 | 1 | 1 | 1 |     0     |      1       |          1          | | 1 | 0 | 0 | 0 |     0     |      0       |          0          | | 1 | 0 | 0 | 1 |     0     |      0       |          1          | | 1 | 0 | 1 | 0 |     0     |      1       |          1          | | 1 | 0 | 1 | 1 |     0     |      1       |          1          | | 1 | 1 | 0 | 0 |     1     |      1       |          1          | | 1 | 1 | 0 | 1 |     1     |      1       |          1          | | 1 | 1 | 1 | 0 |     1     |      1       |          1          | | 1 | 1 | 1 | 1 |     1     |      1       |          1          | +---+---+---+---+-----------+--------------+---------------------+ 

hope helps!


Popular posts from this blog