In [57]:
# The main function that will contain most the of the program's source code
def main():
    # Get the binary input from the user
    binary_input = input("Enter a binary number: ")
    
    # Stores the length of the binary input, this value would be used later
    # For converting the binary input into a decimal value
    exponent_value = len(binary_input)

    # The decimal value of the binary input value 
    total_value = 0
    
    # Make sure that the user entered some value, if not alert the user and rerun the function
    # Also delete all the function variables
    if exponent_value < 1:
        del binary_input
        del exponent_value
        del total_value              
        print("You must enter a value")
        main()
    
    # The loop that will convert the binary input into a decimal value. The loop will iterate 
    # The size of exponent_value.
    for conversion in range(exponent_value):
        # If the binary input indexed value is zero, add 0 to the total_value
        if binary_input[-(conversion+1)] is '0':
            total_value += 0
        # If the binary input indexed value is one, add two with an exponent of the conversion 
        # to the total_value
        # The index value is the conversion + 1 * negative. The reason for this is because when 
        # Iterating through the loop we want to loop from the backwards of the binary input, since
        # The last char's of the binary input have smaller conversions then the first char's
        elif binary_input[-(conversion+1)] is '1':
            total_value += (2 ** conversion)
        # If the binary input indexed value is not either one or zero, the binary input is not valid
        # Alert the user of so, and delete all function variables and rerun function so user could enter
        # An 
        else:
            print("You have entered an invalid binary input")
            del binary_input
            del exponent_value
            del total_value
            main()
    
    # Return the total_value/the converted decimal value
    return total_value
        
        
# Start the main function and store the return vaue in decimal_value    
decimal_value = main()

# Tell the user the converted decimal value
print("The decimal value of your binary number is {}".format(decimal_value))
Enter a binary number: 11001
The decimal value of your binary number is 25
In [ ]: