In [1]:
#defines it as main function
def main():
    #when code runs it is used to have the person running the command give the binary number and the program lists the variable as the binary number
    binaryInput = input("Enter a binary number ==> ")
    #tells how long the binary number is and that number is the value of the variable and is the exponent for when we convert the binary
    exponentValue = len(binaryInput)
    #variable is listed as a value of 0
    totalValue = 0
    
    #function that checks to see if their is a variable inputed by checking to see if the length of the variable is less than 1 and it does this by using the exponent variable because it lists how long the binary number is 
    if exponentValue < 1:
        #deletes the variables to be able to be able to create the loop without confusion
        del binaryInput
        del exponentValue
        del totalValue
        #tells you that you didn't enter anything
        print("All you did was press enter, I need a value to run")
        #tells code to take you back to the beginning of the main function
        main()
        
    #creates a range using the value for exponent value
    for conversion in range(exponentValue):
        #this is the first option and it tells if the number in the binary contains a zero and marks the zero as a actual value of zero
        if binaryInput[conversion] == "0":
            actualValue = 0
        #this is the second option and it determines if the binary contains a one and list the actual value of the one as a 2
        elif binaryInput[conversion] == "1":
            actualValue = 2
        #if other options didn't happen then this part is used because it determined that you didn't use ones and zeros
        else:
            #tells you to only put only ones and zeros
            print("0 or 1 please")
            #deletes the values of the variables
            del binaryInput
            del exponentValue
            del totalValue
            #tells the code to use main function again
            main()
        
        #says the true value will be the equal to actual value with a exponent that is made of exponent value minus 1 this will be how we get the converted number
        trueValue = actualValue ** (exponentValue -1)
    
        
        #checks to see if the actual value is 0 and the exponent is 1 then if they are then the true value is 0
        if actualValue == 0 and exponentValue == 1:
            trueValue = 0
            
        #subtracts 1 from exponent intill it equals 1
        exponentValue -= 1
        
        
        #adds one to the total value to make it the true value
        totalValue += trueValue
        
    #prints the binary and total value in formated text
    print("The decimal value of {} is {}".format(binaryInput, totalValue))
    #quits and restarts kernel
    quit()
        
   
#tells where the main function ends
main()
Enter a binary number ==> 11101101
The decimal value of 11101101 is 237
In [ ]: