def truth_table(expression):
    print " p      q      "  + expression
    length = len( " p      q      "  + expression)
    print length*"-"

    for p in True, False:
        for q in True, False:
            print "" + str(p) + "     " + str(q) + "     " + str(eval(expression))

truth_table("p or q")
truth_table("not(p and q)")