Skip to content
Permalink
Browse files
Create factorialNumber.Py
Q1) Count the number of trailing 0's in a factorial number.
  • Loading branch information
raib10 committed Apr 7, 2021
1 parent 49e75f0 commit 4023ac706fa5242fdd7540644c1f27ce0964abaa
Showing 1 changed file with 24 additions and 0 deletions.
@@ -0,0 +1,24 @@

def get_factorial(n):
if n < 0:
return -1 #if input is 0 break function
else:
factorial = 1
for i in range(1, n+1): # finds all number to multiply
factorial *= i # number multiplied by the indices
return factorial

def trailingZeros(n):
count = 0
i = 5
while(n//i != 0): # function continues until n is no longer divisibly by 5
count += int(n/i) # counts how many 5 there are
i = i * 5 # can be used for any number to figure out the zeros
return count


n = int(input("Type in a number: ")) # User input
fact = get_factorial(n)

print("The factorail number of your input is " + str(fact) + ".")
print("And the number of trailing zeros is: " + str(trailingZeros(n)))

0 comments on commit 4023ac7

Please sign in to comment.