You are on page 1of 3

Experiment: 1

Objective: To implement AND, OR and XOR gates using python.


Theory:
1. AND Gate:
a. In the AND gate, the output of an AND gate attains state 1 if and only if all the inputs are in state 1.
b. Circuit Diagram:

c. Truth Table:

2. OR Gate:
a. In an OR gate, the output of an OR gate attains state 1 if one or more inputs attain state 1.
b. Circuit Diagram:

c. Truth Table:

3. XOR Gate:
a. In an XOR gate, the output of a two-input XOR gate attains state 1 if one adds only input attains state
1.
b. Circuit Diagram:

c. Truth Table:
Codes:
1. AND Gate:
def AND (a,b):
if a == 1 and b == 1:
return 1
else:
return 0

if __name__ == '__main__':
print(" Name : Soumyadeep Manna")
print(" Enrollment No. : A023116120001")
print("----------------------------------")
print(" Truth Table for AND Gate:")
print(" A | B | A AND B")
print(" ------+-------+----------")
print(" 0 | 0 | ",AND(0,0))
print(" 0 | 1 | ",AND(0,1))
print(" 1 | 0 | ",AND(1,0))
print(" 1 | 1 | ",AND(1,1))

2. OR Gate:
def OR (a,b):
if a == 1 or b == 1:
return 1
else:
return 0

if __name__ == '__main__':
print(" Name : Soumyadeep Manna")
print(" Enrollment No. : A023116120001")
print("----------------------------------")
print(" Truth Table for OR Gate:")
print(" A | B | A OR B")
print(" ------+-------+----------")
print(" 0 | 0 | ",OR(0,0))
print(" 0 | 1 | ",OR(0,1))
print(" 1 | 0 | ",OR(1,0))
print(" 1 | 1 | ",OR(1,1))
3. XOR Gate:
def XOR (a,b):
if a != b:
return 1
else:
return 0

if __name__ == '__main__':
print(" Name : Soumyadeep Manna")
print(" Enrollment No. : A023116120001")
print("----------------------------------")
print(" Truth Table for OR Gate:")
print(" A | B | A OR B")
print(" ------+-------+----------")
print(" 0 | 0 | ",XOR(0,0))
print(" 0 | 1 | ",XOR(0,1))
print(" 1 | 0 | ",XOR(1,0))
print(" 1 | 1 | ",XOR(1,1))
Outputs:
1. AND Gate:

2. OR Gate:

3. XOR Gate:

You might also like