#Defining AND circuit def AND(a, b):     #If both values are 1 return 1   if a == 1 and b == 1:     return 1   else:       #Otherwise return 0     return 0   #Defining OR circuit def OR(a, b):     #If either of value is 1 return 1   if a + b == 1 or a == b == 1:     return 1   else:       #Otherwise return 0     return 0   #Defining NOT circuit def NOT(a):     #If the input is 1   if a == 1:       #Return 0     return 0     #If the input is 0   elif a == 0:       #Return 1     return 1   #Defining NAND circuit def NAND(a, b):   a = AND(a, b)   if a == 1:     return 0   else:     return 1   #Defining NOR circuit def NOR(a, b):   a = OR(a, b)   if a == 1:     return 0   else:     return 1   #Defining XOR circuit def XOR(a, b):   a = OR(AND(a, NOT(b)), AND(NOT(a), b))   if a == 1:     return a   else:     return 0   #Defining NXOR circuit def NXOR(a, b):   a = XOR(a, b)   if a == 1:     return 0   elif a == 0:     return 1   #Defining eight() def eight(a, b, c):     # (A ∨ B) ꚛ C = Q   a = XOR(OR(a, b), c)     #Return a   return a   #Defining main() if __name__ == '__main__':     #Printing AND gate   print('Truth Table --- AND GATE')   print('|\tA\t|\tB\t| Output')   print('|\t0\t|\t0\t| ', AND(0, 0))   print('|\t0\t|\t1\t| ', AND(0, 1))   print('|\t1\t|\t0\t| ', AND(1, 0))   print('|\t1\t|\t1\t| ', AND(1, 1))   print()   print()     #Printing OR gate   print('Truth Table --- OR GATE')   print('|\tA\t|\tB\t| Output')   print('|\t0\t|\t0\t| ', OR(0, 0))   print('|\t0\t|\t1\t| ', OR(0, 1))   print('|\t1\t|\t0\t| ', OR(1, 0))   print('|\t1\t|\t1\t| ', OR(1, 1))     print()   print()     #Printing NOT gate   print('Truth Table --- NOT GATE')   print('|\tA\t| Output')   print('|\t0\t| ', NOT(0))   print('|\t1\t| ', NOT(1))     print()   print()     #Printing NAND gate   print('Truth Table --- NAND GATE')   print('|\tA\t|\tB\t| Output')   print('|\t0\t|\t0\t| ', NAND(0, 0))   print('|\t0\t|\t1\t| ', NAND(0, 1))   print('|\t1\t|\t0\t| ', NAND(1, 0))   print('|\t1\t|\t1\t| ', NAND(1, 1))     print()   print()     #Printing NOR gate   print('Truth Table --- NOR GATE')   print('|\tA\t|\tB\t| Output')   print('|\t0\t|\t0\t| ', NOR(0, 0))   print('|\t0\t|\t1\t| ', NOR(0, 1))   print('|\t1\t|\t0\t| ', NOR(1, 0))   print('|\t1\t|\t1\t| ', NOR(1, 1))     print()   print()     #Printing XOR gate   print('Truth Table --- XOR GATE')   print('|\tA\t|\tB\t| Output')   print('|\t0\t|\t0\t| ', XOR(0, 0))   print('|\t0\t|\t1\t| ', XOR(0, 1))   print('|\t1\t|\t0\t| ', XOR(1, 0))   print('|\t1\t|\t1\t| ', XOR(1, 1))     print()   print()     #Printing NXOR gate   print('Truth Table --- NXOR GATE')   print('|\tA\t|\tB\t| Output')   print('|\t0\t|\t0\t| ', NXOR(0, 0))   print('|\t0\t|\t1\t| ', NXOR(0, 1))   print('|\t1\t|\t0\t| ', NXOR(1, 0))   print('|\t1\t|\t1\t| ', NXOR(1, 1))   print()   print()     #Printing (A ∨ B) ꚛ C = Q   print('Truth Table --- NXOR GATE')   print('|\tA\t|\tB\t| Output')   print('|\t0\t|\t0\t| ', NXOR(0, 0))   print('|\t0\t|\t1\t| ', NXOR(0, 1))   print('|\t1\t|\t0\t| ', NXOR(1, 0))   print('|\t1\t|\t1\t| ', NXOR(1, 1))     #Printing  (A ∨ B) ꚛ C = Q gate (NXOR for 3 value inputs)   print('Truth Table for (A ∨ B) ꚛ C = Q')   print('|\tA\t|\tB\t|\tC\t| Output')   print('|\t0\t|\t0\t|\t0\t|', eight(0, 0, 0))   print('|\t0\t|\t0\t|\t1\t|', eight(0, 0, 1))   print('|\t0\t|\t1\t|\t0\t|', eight(0, 1, 0))   print('|\t0\t|\t1\t|\t1\t|', eight(0, 1, 1))   print('|\t1\t|\t0\t|\t0\t|', eight(1, 0, 0))   print('|\t1\t|\t0\t|\t1\t|', eight(1, 0, 1))   print('|\t1\t|\t1\t|\t0\t|', eight(1, 1, 0))   print('|\t1\t|\t1\t|\t1\t|', eight(1, 1, 1))

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Can provide a description outlining which option chosen and a description of how the code works and how to use it.

Also can you fix the code. 

#Defining AND circuit

def AND(a, b):

 

  #If both values are 1 return 1

  if a == 1 and b == 1:

    return 1

  else:

 

    #Otherwise return 0

    return 0

 

#Defining OR circuit

def OR(a, b):

 

  #If either of value is 1 return 1

  if a + b == 1 or a == b == 1:

    return 1

  else:

 

    #Otherwise return 0

    return 0

 

#Defining NOT circuit

def NOT(a):

 

  #If the input is 1

  if a == 1:

 

    #Return 0

    return 0

 

  #If the input is 0

  elif a == 0:

 

    #Return 1

    return 1

 

#Defining NAND circuit

def NAND(a, b):

  a = AND(a, b)

  if a == 1:

    return 0

  else:

    return 1

 

#Defining NOR circuit

def NOR(a, b):

  a = OR(a, b)

  if a == 1:

    return 0

  else:

    return 1

 

#Defining XOR circuit

def XOR(a, b):

  a = OR(AND(a, NOT(b)), AND(NOT(a), b))

  if a == 1:

    return a

  else:

    return 0

 

#Defining NXOR circuit

def NXOR(a, b):

  a = XOR(a, b)

  if a == 1:

    return 0

  elif a == 0:

    return 1

 

#Defining eight()

def eight(a, b, c):

 

  # (A ∨ B) ꚛ C = Q

  a = XOR(OR(a, b), c)

 

  #Return a

  return a

 

#Defining main()

if __name__ == '__main__':

 

  #Printing AND gate

  print('Truth Table --- AND GATE')

  print('|\tA\t|\tB\t| Output')

  print('|\t0\t|\t0\t| ', AND(0, 0))

  print('|\t0\t|\t1\t| ', AND(0, 1))

  print('|\t1\t|\t0\t| ', AND(1, 0))

  print('|\t1\t|\t1\t| ', AND(1, 1))

  print()

  print()

 

  #Printing OR gate

  print('Truth Table --- OR GATE')

  print('|\tA\t|\tB\t| Output')

  print('|\t0\t|\t0\t| ', OR(0, 0))

  print('|\t0\t|\t1\t| ', OR(0, 1))

  print('|\t1\t|\t0\t| ', OR(1, 0))

  print('|\t1\t|\t1\t| ', OR(1, 1))

 

  print()

  print()

 

  #Printing NOT gate

  print('Truth Table --- NOT GATE')

  print('|\tA\t| Output')

  print('|\t0\t| ', NOT(0))

  print('|\t1\t| ', NOT(1))

 

  print()

  print()

 

  #Printing NAND gate

  print('Truth Table --- NAND GATE')

  print('|\tA\t|\tB\t| Output')

  print('|\t0\t|\t0\t| ', NAND(0, 0))

  print('|\t0\t|\t1\t| ', NAND(0, 1))

  print('|\t1\t|\t0\t| ', NAND(1, 0))

  print('|\t1\t|\t1\t| ', NAND(1, 1))

 

  print()

  print()

 

  #Printing NOR gate

  print('Truth Table --- NOR GATE')

  print('|\tA\t|\tB\t| Output')

  print('|\t0\t|\t0\t| ', NOR(0, 0))

  print('|\t0\t|\t1\t| ', NOR(0, 1))

  print('|\t1\t|\t0\t| ', NOR(1, 0))

  print('|\t1\t|\t1\t| ', NOR(1, 1))

 

  print()

  print()

 

  #Printing XOR gate

  print('Truth Table --- XOR GATE')

  print('|\tA\t|\tB\t| Output')

  print('|\t0\t|\t0\t| ', XOR(0, 0))

  print('|\t0\t|\t1\t| ', XOR(0, 1))

  print('|\t1\t|\t0\t| ', XOR(1, 0))

  print('|\t1\t|\t1\t| ', XOR(1, 1))

 

  print()

  print()

 

  #Printing NXOR gate

  print('Truth Table --- NXOR GATE')

  print('|\tA\t|\tB\t| Output')

  print('|\t0\t|\t0\t| ', NXOR(0, 0))

  print('|\t0\t|\t1\t| ', NXOR(0, 1))

  print('|\t1\t|\t0\t| ', NXOR(1, 0))

  print('|\t1\t|\t1\t| ', NXOR(1, 1))

  print()

  print()

 

  #Printing (A ∨ B) ꚛ C = Q

  print('Truth Table --- NXOR GATE')

  print('|\tA\t|\tB\t| Output')

  print('|\t0\t|\t0\t| ', NXOR(0, 0))

  print('|\t0\t|\t1\t| ', NXOR(0, 1))

  print('|\t1\t|\t0\t| ', NXOR(1, 0))

  print('|\t1\t|\t1\t| ', NXOR(1, 1))

 

  #Printing  (A ∨ B) ꚛ C = Q gate (NXOR for 3 value inputs)

  print('Truth Table for (A ∨ B) ꚛ C = Q')

  print('|\tA\t|\tB\t|\tC\t| Output')

  print('|\t0\t|\t0\t|\t0\t|', eight(0, 0, 0))

  print('|\t0\t|\t0\t|\t1\t|', eight(0, 0, 1))

  print('|\t0\t|\t1\t|\t0\t|', eight(0, 1, 0))

  print('|\t0\t|\t1\t|\t1\t|', eight(0, 1, 1))

  print('|\t1\t|\t0\t|\t0\t|', eight(1, 0, 0))

  print('|\t1\t|\t0\t|\t1\t|', eight(1, 0, 1))

  print('|\t1\t|\t1\t|\t0\t|', eight(1, 1, 0))

  print('|\t1\t|\t1\t|\t1\t|', eight(1, 1, 1))

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY