I am trying to create a program that will help solve a complex logic gate scheme. To do this, I tried to build the main logical gate and checked the test for them:
def isbit(a):
if(a==0 | a==1) : return True
return False
/
def Nor(a,b):
assert(isbit(a) & isbit(b)) ,"inputs to Nor are not Bit Type"
return not(a|b)
def Or(a,b):
assert(isbit(a) & isbit(b)) ,"inputs to or are not Bit Type"
return (a|b)
def Xor(a,b):
assert(isbit(a) & isbit(b)) ,"inputs to or are not Bit Type"
return (a^b)
def And(a,b):
assert(isbit(a) & isbit(b)) ,"inputs to or are not Bit Type"
return (a&b)
def Nand(a,b):
assert(isbit(a) & isbit(b)) ,"inputs to or are not Bit Type"
return not(And(a,b))
def Not(a):
assert(isbit(a)) ,"inputs to or are not Bit Type"
return not(a)
def main():
pass
if __name__ == '__main__':
main()
x=1
y=1
print Xor(Nor(And(x,y),Nand(x,y)),Or(And(x,y),Nand(x,y)))
the script returns:
Message File Name Line Position
Traceback
<module> <module1> 51
Nor <module1> 18
AssertionError: inputs to Nor are not Bit Type
I do not understand why this raises my statement if I only send 1s input functions .
source
share