q = False
r = True
test = ['p and not q', 'not not p', 'not(p and q)', 'q or not p and r',
    'q or not (p and r)', 'p or q or r', 'p or q or r and False']
for t in test:
    pass
Альтернатива eval в Python