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 Full-Adder in Python 3.5.0 Problem 1: Put a comment

ID: 3576194 • Letter: T

Question

This is the simulation of a Full-Adder in Python 3.5.0

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

adds two values together and returns the remaining to add def XOR (x, y) return (x y) def Full Adder (a, b, c in) s XOR (XOR (a, b), c in) C out (a and b) or (c in and XOR (a, b return. (s, c out) def main. bool (int (input ("Please enter a 0 or 1: y bool (int (input ("Please enter another 0 or 1: bool (int (input ("Please enter cin (0 or 1) print (Full Adder (x,y, z)) return if name main main

Explanation / Answer

since you have the program I am going to write down comments of each line starting from first one which is

def XOR (x, y) : # This is a XOR function definition which is called in below line of code (x and y are the variables on which XOR operation will be performed)

# This line is performing XOR operation on the two variables, that is x and y. If (x != y) it will return false, that is 1; else this line will return 0 to the calling function

# This is FullAdder function definition where operation of full adder will be performed. a, b are the variables on which full adder operation is performed and c_in is carry in variable which is also required in operating full adder (Please refer to the block diagram of full adder)

# In this line s indicates sum in which first XOR is called on variables a, b to perform XOR operation and then result of that XOR operation and c_in is again called returning value of which will be sum s.

#c_out means carry out which is essential in full adder output. carry is calculated by performing these three operations together. So this line can be broken into three parts

i) and operation between variables a and b

ii) XOR operation between variables a and b

iii) and operation between variables c_in and result of ii

iv) or operation is performed between result of i and iii to get c_out

# after getting sum (s) and carry out (c_out) these values will be returned to the calling function.

# Definition of main function where all other function will be called

# input for variable x is taken by the user who want to perform full adder operation with the help of this program, since this is python 3.5.0 what python 3 does that it takes input as string, that is why input is first typecast(converted) into int and after that in boolean because all these operations are boolean operations

# input for variable y is taken by the user who want to perform full adder operation with the help of this program, since this is python 3.5.0 what python 3 does that it takes input as string, that is why input is first typecast (converted) into int and after that in boolean because all these operations are boolean operations

# input for variable z is taken by the user (which is c_in) who want to perform full adder operation with the help of this program, since this is python 3.5.0 what python 3 does that it takes input as string, that is why input is first typecasted (converted) into int and after that in bool because all these operations are boolean operations

print (FullAdder(x, y), z) # Since we have all the information from user (user input). So FullAdder function is called here which is explained above, and after getting the returning value which is going to be output of the program is printed in this line only

# This line means termination of the program, means when program reaches this line it will be terminated

# This line is very important actually since i mentioned about previous line that program will be terminated there. So your mind must be thinking that how these line will be executed. So this is another feature of python; unlike other languages like c/c++ and java python provides freedom to start from whatever function you want to start with. For example in c program will always start with the main function or in java program will start with public static void main (String args []). But in python program have freedom to call whatever function he wants to be executed first. Although this line has called main function as we can see if _name_ == "_main_" is written here and main() in the next line.

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