My goal is to find any value other than 1 or 0 in list and throw an error and break out of the loop.
At the moment it can check for any non-integer values just fine but i wish to avoid certain numbers (2-9). I tried checking if x != '1' or x != '0' but that didn't work.
I appreciate any help.
decimalTotal = 0
digit = 0
index = 0
power = 7
flag = 'false'
#get an 8-bit binary number
binaryNumber = input("Please enter an 8-bit binary number: ")
binary_list = list(binaryNumber)
if len(binary_list) != 8:
print()
print("You did not enter an 8-bit length.")
print()
for x in binary_list:
while (power >= 0):
try:
(int(binary_list[index]))
except ValueError:
flag = 'true'
break
else:
decimalTotal += (int(binary_list[index])) * (2**(power))
index += 1
power -= 1
if flag == 'false':
print()
print("The decimal value is: ", decimalTotal)
print()
else:
print()
print("Invalid binary value entered.")
print()