Here's what i am trying to do. I am basically having a truth-table for two boolean formulas:
x=[True, False]
y=[True, False]
a=[]
for i in x:
for z in y:
a.append([i, z])
Now I want to input some boolean expression and check it in every "row" of my truth-table. I tried this:
p=None
q=None
result=[]
exp=input("Type your boolean expression using p and q as variables: ")
for i in a:
p, q = i[0], i[1]
result.append(exp)
print(result)
But when I try to type some boolean expression as input, for example:
(not p) or q
It uses at as a string. But if I do this:
exp=bool(input("Type your boolean expression using p and q as variables: "))
then every non-empty string would be regarded as True
in bool
. How can I solve this?