binary = input("Please enter a binary number: ") end = ((len(binary))-1) #Set a marker to start at the left most digit count = 1 total = 0 for i in range (len(binary)): value = int(binary[end]) end = (end -1) #To shift from the left most digit until the right most digit total = (total + (value * count)) count = count * 2 #To change the value of the column to be calculated next (2,4,8,16 etc) print ("The number you entered is: " + str(total))
SUGGESTIONS
We would love to hear from you |
SUBSCRIBE
To enjoy more benefits |