I am trying to solve the problem in the title, and I'm getting an IndexError.
def count_zeros(number:int) -> int:
number = str(number)
i = 0
j = -1
while number[j] == '0'
i += 1
j += -1
return i
This code spits out the IndexError only when the number is 0. I cannot figure out why.
>>>count_zeros(0)
IndexError Traceback (most recent call last)
<ipython-input-45-688099e7700c> in <module>
----> 1 end_zeros(0)
<ipython-input-43-181de92af60c> in end_zeros(number)
4 i = 0
5
----> 6 while number[j] == '0':
7 i += 1
8 j -= 1
IndexError: string index out of range