Question about the number of last zeros of Python Factory Value

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

When I ran the part of the assistant terminal ZeroCount (20), I got 7. When I do 20! with a calculator, it's true that there are 7 zeros, but how do I use this as a string method to get 4?

python

2022-09-20 10:53

1 Answers

def terminalZerosOfFactorial(n):
    fac = 1
    for i in range(1, n+1):
        fac *= i
    s = str(fac)
    cnt = 0
    while s[-(cnt+1)] != "0":        
        cnt += 1
    return cnt    
def terminalZerosOfFactorial(n):
    cnt = 0
    for i in range(1, n+1):
        while i%5 == 0:
            cnt += 1
            i %= 5
    return cnt


2022-09-20 10:53

If you have any answers or tips


© 2022 pinfo. All rights reserved.