I'm trying to work out the last digit of a bar code however I'm having trouble with the second and last while loops.
They don't assign any new values to the variables total or mOf10. It instead leaves them as 0 and I don't understand why.
while True:
number = input("Enter a 7 digit number please.")
if len(number) == 7:
try:
number = int(number)
except ValueError:
print("Please enter a number")
else:
break
else:
print("Please enter a valid number.")
print(number) #DELETE THIS BIT LATER!
i = 0
total = 0
while (i < 7 == True):
global total
f = str(number)[i]
if int(f) % 2 == 1:
total = total + int(f) * 3
else:
total = total + int(f)
i += 1
print(total)
mOf10 = 0
while True:
global mOf10
if mOf10 >= total:
break
else:
mOf10 += 10
finalD = mOf10 - total
print(finalD)
It prints out what ever 7 digit number you put in however it doesn't output the total or multiple of 10 as anything. They just come out as 0.
My teachers only solution to this was a lot of if/else statements.