109k views
0 votes
Write a program that lets a user enter N and that outputs N! (N factorial, meaning N*(N-1)*(N-2)*..\.\*2*1). Hint:Use a loop variable i that counts from total-1 down to 1. Compare your output with some of these answers: 1:1, 2:2, 3:6, 4:24, 5:120, 8:40320.

1 Answer

7 votes

Answer:

The program is as follows:

num = int(input("Number: "))

fact = 1

for i in range(1,num+1):

fact*=i

print(fact)

Step-by-step explanation:

This gets integer input from the user

num = int(input("Number: "))

This initializes factorial to 1

fact = 1

The following iteration calculates the factorial of the integer input

for i in range(1,num+1):

fact*=i

This prints the calculated factorial

print(fact)

User DACrosby
by
3.5k points