From 4023ac706fa5242fdd7540644c1f27ce0964abaa Mon Sep 17 00:00:00 2001 From: "Bibeak Rai (raib10)" Date: Wed, 7 Apr 2021 15:50:45 +0100 Subject: [PATCH] Create factorialNumber.Py Q1) Count the number of trailing 0's in a factorial number. --- factorialNumber.Py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 factorialNumber.Py diff --git a/factorialNumber.Py b/factorialNumber.Py new file mode 100644 index 0000000..b65448b --- /dev/null +++ b/factorialNumber.Py @@ -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)))