#This is the main function that will decode binary and show you its value
def main ():
#This is the Binary number that the user willwant the program to decode
binaryInput = input("Enter a number, binary only please > ")
#This is the vale of the expponet, it's value depends oin ther amount of one's and zero's in the binary number
exponentValue = len(binaryInput)
totalValue = 0
#This if statement will only start if nothing is entered
if exponentValue < 1:
#This is gonna delete the binary number that the user put in
del binaryInput
#This deletes the exponets value
del exponentValue
#this gets rid of the total value
del totalValue
#Prints a message that let's the user know that the program knows that they did not put anything in as a decimal value
print("I know what you did, only pressed enter huh? Nice try but I need a Biary number.")
#This restarts the program
main()
#this will tell the program that the ones are equal to 2 and zeros are 0
for conversion in range(exponentValue):
#this part says that if there is a zero, it equals zero
if binaryInput[conversion] =="0":
actualvalue = 0
#if there is a one in the binary number, it equals 2
elif binaryInput[conversion] == "1":
actualvalue = 2
# what happens if the user puts in anything other than ones and zeros
else:
#shows this message
print("That's not a Binary number silly, its only 0 and 1")
#This is gonna delete the binary number that the user put in
del binaryInput
#deletes exponent's value
del exponentValue
#deletes the total value
del totalValue
#restarts the program
main()
#this will give me the true value of the binary number saying that it is the actual value muitiplied by the the exponet value -1 exponent
trueValue = actualvalue ** (exponentValue -1)
#This is just in case the binary number put in is 0, it makes the exponet value equal 1, because 0 to the power of 0 equals 1
if actualvalue == 0 and exponentValue == 1:
trueValue = 0
#this will make the exponet value go down by one so its accurate
exponentValue -= 1
totalValue += trueValue
#this will show the value
print("The decimal value of {} is {}".format(binaryInput, totalValue))
main()