I am very new to Python and coding in general. For my school assignment I have to create a program that converts from binary to decimal, but first I need also to check if input is binary. Basically - I have separate code that check if input is correct and another one that converts. Any advice on how to combine those two? This is my first task ever and I really got stuck. Please note that I am not allowed to use any built-in functions. Appreciate any advice about what mistake do I do here?
my_binary = input("Enter binary number: ")
decimal = 0
index = 0
exponent = len(my_binary) - 1
def b_to_d(my_binary):
for character in my_binary:
if character != '0' and character != '1':
print ('Number is not binary!')
return False
print ('Number is binary')
return True
b_to_d(str(my_binary))
while True and index != len(my_binary):
decimal += int(my_binary[index]) * 2**exponent
index += 1
exponent -= 1
print(decimal)