161k views
13 votes
Write a Python function that takes a positive integer N and returns the factorial of N, i.e., N! The factorial of N, denoted N!, is the product of the integers from 1 to N. (1 Point)

User Allenskd
by
4.9k points

1 Answer

14 votes

Answer:

The python function is as follows:

def fact(N):

factorial = 1

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

factorial = factorial * i

return(factorial)

Step-by-step explanation:

This line defines the function

def fact(N):

This line initializes the product of 1 to N to 1

factorial = 1

This line iterates through 1 to N

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

This line calculates the product of 1 to N i.e. factorial

factorial = factorial * i

This line returns the factorial

return(factorial)

User Jaap
by
4.9k points