I am trying to calculate the number of trailing zeros in a factorial.
def count(x):
    zeros = 0                     
    for i in range (2,x+1): 
        print(i)
        if x > 0:
            if i % 5 == 0:       
                print("count")    
                zeros +=1       
        else:
            ("False")
    print(zeros)        
count(30)
I think the number of trailing zeros is incorrect.
When using count(30), there are 7 trailing 0's in 30. However it is returning 6.
def count (x):
    i = 5
    zeros = 0
    while x >= i:
        zeros += x // i
        i *= 5
    return zeros
print(count(30))
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With