python - Why does my code return 1 when the given number has more zeroes? -
if have method can me appreciate help, tried best write code calculates number of zeroes in given number.
here's code tried:
def zrc(n): count=0 while n%10==0 , n!=0: n=n%10 count=count+1 return count print(zrc(2500))
it gives 1 output of code, while must print 2, numbers 36, gives 0 output, problem? know there must problem while...
if n%10
zero, n
0 in next step, condition fulfilled after first loop. want use //
instead of %
:
def zrc(n): count = 0 while n%10 == 0 , n != 0: n //= 10 count += 1 return count
Comments
Post a Comment