Am trying to make a simple program to convert binary number to decimal number. I'd like to first write a condtion whether to check the given number is a binary or not.
How do i do that?
Except that, the program works normally without any errors but am afraid when a non binary number is given, it still does the job.
Input
print("Binary to Decimal")
bin = input("Give a binary number : ")
bin = [int(i) for i in bin]
powers = [i for i in range(len(bin)-1,-1,-1)]
for i in range(len(bin)):
bin[i] = bin[i] * 2**(powers[i])
decimal = sum(bin)
print("The corresponding Decimal digit is : %d"%(decimal))
Output
Binary to Decimal
Give a binary number : 101
The correspnding Decimal digit is : 5
Also if u find any corrections or want to make any suggestions, please feel free to suggest me below.