我怎样写“如果p那么q”来计算真值表?

2024-03-28 13:22:55 发布

您现在位置:Python中文网/ 问答频道 /正文

Write a Python program that produces a truth table for the following statements:

  • p and q
  • p or q
  • if p, then q
  • p if and only if q

To earn credit, you must calculate the truth values.

我可以使用:

print(getSym(p), getSym(q), getSym(p and q), getSym(p or q),

找出“and”和“or”语句

def getSym(x):
    if x:
        return 'T'
    else:
        return 'F'

values = [True, False]

print('and')
for p in values:
    for q in values:
        print(getSym(p), getSym(q), getSym(p and q), getSym(p or q), getSym())

我已经得到了前两个语句来输出一个正确的真值表


Tags: orandtheinforreturnifthat