def nand(a, b):
return (not a) or (not b)
def nand_or(a, b):
return (nand(a, 1) is False and nand(b, 1) is True) or (nand(a, 1) is True and nand(b, 1) is False)
def nand_and(a, b):
return (nand(a, 1) is False and nand(b, 1) is False)
不知道这样是不是满足要求
mulderlover试一下就知道你那样写的结果不对了。
def nand(a,b):
c=a and b
return(not c)
def nand_or(a,b):
return nand(nand(a,a),nand(b,b))
def nand_and(a,b):
return nand(nand(a,b),nand(a,b))
下面两个没有用到运算符,直接调用函数
nand = lambda a, b: not (a and b)
nand_or = lambda a, b: (a or b) and nand(a, b)
nand_and = lambda a, b: not nand(a, b)
for k in range(1,51):
total += (k*k)