Monday, 3 March 2014

Logic Gates in Python

def AndGate():
    print("Welcome to the And gate simulator")
    a = int(input("Please enter 1 or 0"))
    b = int(input("Please enter 1 or 0"))
    if a==1 and b==1:
        c=1
    elif a==1 and b==0:
        c=0
    elif a==0 and b==1:
        c=0
    elif a==0 and b==0:
        c=0
    print(c)
def OrGate():
    print("Welcome to the Or gate simulator")
    a = int(input("Please enter 1 or 0"))
    b = int(input("Please enter 1 or 0"))
    if a==1 and b==1:
        c=1
    if a==1 and b==0:
        c=1
    if a==0 and b==1:
        c=1
    if a==0 and b==0:
        c=0
    print(c)
def NotGate():
    print("Welcome to the Not gate simulator")
    a = int(input("Please enter 1 or 0"))
    if a==1:
        c=0
    if a==0:
        c=1
    print(c)
   
def NandGate():
    print("Welcome to the Nand gate simulator")
    a = int(input("Please enter 1 or 0"))
    b = int(input("Please enter 1 or 0"))
    if a==1 and b==1:
        c=0
    elif a==1 and b==0:
        c=1
    elif a==0 and b==1:
        c=1
    elif a==0 and b==0:
        c=1
    print(c)
def NorGate():
    print("Welcome to Nor gate simulator")
    a = int(input("Please enter 1 or 0"))
    b = int(input("Please enter 1 or 0"))
    if a==1 and b==1:
        c=0
    if a==1 and b==0:
        c=0
    if a==0 and b==1:
        c=0
    if a==0 and b==0:
        c=1
    print(c)
def XorGate():
    print("Welcome to Xor gate simulator")
    a = int(input("Please enter 1 or 0"))
    b = int(input("Please enter 1 or 0"))
    if a==1 and b==1:
        c=0
    elif a==1 and b==0:
        c=1
    elif a==0 and b==1:
        c=1
    elif a==0 and b==0:
        c=0
    print(c)

No comments:

Post a Comment