Mar-10-2021, 04:49 PM
(Mar-07-2021, 09:03 AM)saratha Wrote: I wrote this code to count the zeros at the beginning. While i excecuted it for '0001' it gave the right answer(3) but when i ran for '0000' it gives me 1. Can someone explain why? And what should i do for this?
Just for fun!
def beginning_zeros(x): count = 0 for i in range(len(x)): if x[i] == '0': count += 1 else: pass return count print(beginning_zeros('0.010')) print(beginning_zeros('1,000,010.05'))