Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is the simulation of a 4-2 Encoder in Python 3.5.0 Problem 1: Put a comment

ID: 3576196 • Letter: T

Question

This is the simulation of a 4-2 Encoder in Python 3.5.0

Problem 1: Put a comment for each line of code to show your clear understanding of the program below:

def encoder (a c, d) if (d True) return (False, False) elif (c True) return (False, True) elif (b True) return (True, False) else: return True, True) def main x bool (int (input ("Please enter a 0 or 1: y bool (int (input ("Please enter another 0 or 1: x1 bool (int (input ("Please enter another 0 or 1 1 bool (int (input ("Please enter the last 0 or 1: print (encoder (x, y x1, y1)) return. if name main main

Explanation / Answer

def encoder(a,b,c,d)://A function is defined with four parameters.

// control statement if else is defined
if(d== True):
return(false,False) // if d is true then it returns false and false.
elif(c==True):
return (False,True) // if c is true then it returns false and true.
elif(b==True):
return (true,False) // if b is true then it returns true and false.
else:
return(true,true) // and for any other case differen from the above
it will return true and true


def main():

// defining inputs in the main function which return the value in only true and false

x= bool(int(input("please enter a 0 or 1:")))
y= bool(int(input("please enter another 0 or 1:")))
x1= bool(int(input("please enter another 0 or 1:")))
y1= bool(int(input("please enter the last 0 or 1:")))
print (encoder(x,y,x1,y1)) // calling encoder function.
return

if_name_ =="_main_": //Every Python module has it's __name__ defined and
if this is __main__, it implies that the module is
being run standalone by the user and we can do
corresponding appropriate actions.
main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote