Write a program that prompts the user to input a binary number and display its decimal equivalent.

Source Code

binary = input("Enter a binary number: ")
decimal=0
place=0
for i in reversed(binary):
    decimal = decimal + int(i)*pow(2,place)
    place=place+1
print("Decimal representation of binary",binary,"is",decimal)

Output

Enter a binary number: 1100
Decimal representation of binary 1100 is 12