【发布时间】:2016-04-26 13:24:53
【问题描述】:
我正在尝试在 python 中创建一个逻辑门模拟程序,以便用户可以选择他们想要模拟的逻辑门的类型。一旦选择,他们就可以输入输入,程序应该将所选逻辑门的输出值返回给用户。
这是我目前所拥有的:
print ("Logic Gate Simulation")
def AND (a,b):
if a == 1 and b == 1:
return 1
else:
return 0
def NAND (a,b):
if a == 1 and b == 1:
return 0
else:
return 1
def OR(a,b):
if a == 1:
return 1
elif b == 1:
return 1
else:
return 0
def NOR (a,b):
if a != b:
return 1
else:
return 1
def Main():
question = input("what type of gate do you want to simulate - OR, AND or NAND? ")
if question == 'AND':
a = input("enter value for input 1")
b = input("enter value for input 2")
x= AND(a,b)
print (x)
else:
print ("")
Main()
当我运行程序并输入 AND 时,输入 1 和 1 它仍然返回 0,我不明白为什么。
【问题讨论】: