Question about the number of last zeros of Python Factory Value

Asked 2 years ago, Updated 2 years ago, 19 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


© 2024 OneMinuteCode. All rights reserved.