Answer to Question #178335 in Python for tas

Question #178335

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. 


1
Expert's answer
2021-04-11T19:25:32-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS