I'm currently in year 10 (9th grade) and I'm making a program for school that converts binary numbers into decimal numbers and vice versa on python. My coding knowledge isn't great so the program may not be as efficient as it can be so please bear with me.
The code below is checking whether the user input only contains 1's and 0's and that it does not go over the maximum of 8 bits. When I run it and input an invalid number, it works and loops just fine but when I input a valid number, it keeps on going back to the input command and asks me to input something instead of escaping the loop and moving onto the next thing. Please help!
max_8bits = 1
only_bin = 1
while max_8bits > 0 or only_bin > 0:
b2d_num = input("Enter a binary number:")
for i in range(len(b2d_num)):
if b2d_num[i] == "0" or b2d_num[i] == "1":
if i == len(b2d_num):
only_bin -= 1
else:
print("Only enter a binary number! (0's and 1's)")
break
if len(b2d_num) > 8:
print("Only enter up to 8 bits!")
elif len(b2d_num) <= 8:
max_8bits -= 1