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

Please help me with this question, thank you! Suppose you were working on some P

ID: 3876327 • Letter: P

Question

Please help me with this question, thank you!

Suppose you were working on some Python code to convert numbers from binary to decimal form....

Suppose you were working on some Python code to convert numbers from binary to decimal form. Suppose your mischievous cat walked across your keyboard while you were getting a cup of coffee, and as a result several important pieces of code have gone missing. For each missing piece of code, select the answer that will enable the function BinToDec to convert positive integers from binary to decimal form, without modifying any of the other pieces of code. Note: binary_in is a Python list, representing the number in binary form. Example: The number 10 in binary would be input as [1, 0, 1, 0]. def BinToDec(binary_in) # initialize decimalout = 0 # add up the binary expression of the decimal number for position in Choose... - decimal-out decimal-out + binary-in[len(binary-in)-position-1]"(2*-Choose ) = v return (decimal_out)

Explanation / Answer

It will be for position in range(0,len(binary_in))

so your for loop will run from range 0 to binary_in length

and

decimal_out=decimal_out+binary_in[len(binary_in)-position-1]*(2**position)

so it will start from power 0 and increase as loop run

I hope this solves your problem

Comment if you have any problem in above code

And please give it a thumbs up if it solved your problem :)

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