Write a program that lets a user enter N and that outputs N! (N factorial, meaning N*(N-1)*(N-2)*..\.\*2*1). Hint: Initialize a variable total to N (where N is input), and 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.

Respuesta :

Answer:

N = int(input("Enter a number: "))

total = N

for i in range(N-1, 1, -1):

   total *= i

   

print(total)

Explanation:

Ask the user for the input, N

Set the total N at the beginning

Create a for loop that iterates from N-1 to 1 inclusively. Inside the loop, multiply each number in that range and add the result to the total.

When the loop is done, print the total to see the result