Note: I am not an official teacher or GSI for any of the courses listed on this site unless otherwise stated. Any problems and notes are created from my own observations and may not accurately reflect the course's content.

Iteration #1

The convert_binary function takes a number in base 2 (binary), b, and returns the decimal representation of the number. Refer to the doctests for examples how to use the convert_decimal function.

def convert_binary(b):
	""" Convert a binary number to decimal
           
           >>> convert_binary(10110)
           22
           >>> convert_binary(111)
           7
           >>> convert_binary(0)
           0
           >>> convert_binary(1000)
           8
           """
	______________________ , factor = ______________________ , 1
	while b:
		b, last = b // 10, b % 10
		______________________ = ____________________________________________
		factor = ______________________
	return ______________________

Solution

Have a question? Found an error? Email me at imran.khaliq@berkeley.edu with the URL of the page and a short description.