热线电话:13121318867

登录
2019-04-12 阅读量: 545
python中的add函数

如果两个输入都是1,AND门给出1的输出,否则给出0。

# Python3 progarm to illustrate

# working of AND gate

def AND (a, b):

if a == 1 and b == 1:

return True

else:

return False

# Driver code

if __name__=='__main__':

print(AND(1, 1))

print("+---------------+----------------+")

print(" | AND Truth Table | Result |")

print(" A = False, B = False | A AND B =",AND(False,False)," | ")

print(" A = False, B = True | A AND B =",AND(False,True)," | ")

print(" A = True, B = False | A AND B =",AND(True,False)," | ")

print(" A = True, B = True | A AND B =",AND(True,True)," | ")

输出:

True
+---------------+----------------
| AND Truth Table | Result |
A = False, B = False | A AND B = False |
A = False, B = True | A AND B = False |
A = True, B = False | A AND B = False |
A = True, B = True | A AND B = True |
0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子