Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
210CT-CW/factorialNumber.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
24 lines (19 sloc)
726 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |