write a python script to write a 3 variables and posiable logic gates truth table generator
时间: 2023-03-13 13:04:53 浏览: 172
How to Think Like a Computer Scientist- Learning with Python 3 黄
你好!我可以写一个 Python 脚本来生成三个变量和可能的逻辑门真值表。下面是示例代码:# 定义变量
A = 0
B = 0
C = 0# 定义逻辑门
def AND(a,b):
return a and bdef OR(a,b):
return a or bdef NOT(a):
return not a# 生成真值表
for a in [0, 1]:
for b in [0, 1]:
for c in [0, 1]:
A = a
B = b
C = c
print("A", a, "B", b, "C", c, "AND", AND(A,B), "OR", OR(A,B), "NOT", NOT(C))
阅读全文