我已经做了一个逻辑门,它接收两个输入,然后在这种情况下,这些输入将传入一个与门。例如,用户将输入0和0,然后与门将处理为0。你知道吗
这里的问题是,当我们使用IF语句来确定我们的两个输入时,它们不会被识别,否则程序中的其他所有内容都无法处理这两个输入以及输出的临时存储。你知道吗
A = input("Enter a value of 1 or 0: ")
B = input("Enter a value of 1 or 0: ")
print(A)
print(B)
所以上面的部分我可以输入输入并为它创建一个存储。 程序告诉我A和B是无法识别的,所以有人知道我做错了什么吗?你知道吗
这就是问题所在:从here到else语句的所有内容都被忽略。你知道吗
def first_AND ():
if A == 0 and B == 0:
AND_1()
print(AND)
print("Now solve the XOR gate")
gate_path_A()
elif A == 1 and B == 0:
AND_2()
print(AND)
print("Now solve the XOR gate")
gate_path_A()
elif A == 0 and B == 1:
AND_3()
print(AND)
print("Now solve the XOR gate")
gate_path_A()
elif A == 1 and B == 1:
AND_4()
print(AND)
print("Now solve the XOR gate")
gate_path_A()
else:
print("Error")
它跳过了我所有的elif语句,只打印了一个错误。你知道吗
def AND_1():
print(A & " AND " & B & " = 0")
AND = 0
def AND_2():
print(A & " AND " & B & " = 0")
AND = 0
def AND_3():
print(A & " AND " & B & " = 0")
AND = 0
def AND_4():
print(A & " AND " & B & " = 1")
AND = 1
我为您清理了代码:您应该阅读python语法f.e.https://docs.python.org/2/reference/index.html(对于2.7.x)并编写一些教程
主程序
相关问题 更多 >
编程相关推荐