Write a function that finds the factorial of a number. The function should get a number from the user as an argument and should print the factorial of the number as the user requested.
def my_factorial():
# ask user to input the number
N = int(input("Input a number to calculate factorial: "))
# initialize the variable to contain factorial with 1
factorial = 1
# for all numbers between 1 and N
for i in range(1, N + 1):
factorial *= i # multiply the result by the current number
print(factorial) # print the final result
Comments
Leave a comment