katiebreon2297 katiebreon2297
  • 18-01-2021
  • Computers and Technology
contestada

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)

Respuesta :

MrRoyal
MrRoyal MrRoyal
  • 20-01-2021

Answer:

The python function is as follows:

def fact(N):

   factorial = 1

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

       factorial = factorial * i

   return(factorial)

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)

Answer Link

Otras preguntas

A piece of plywood 24 inches wide is cut into strips 2 1/2 inches wide. How many strips of this width can be cut?
What are examples of weathering by wind
Christy drove 270 miles in 6 hours at a constant speed how long would it take her to drive 405 miles at the same speed ?
How many bones does a full grown male have in his body?
what is 12/21 reduced to
which expression is not equivalent to the others? explain a.-16x+5(2x+8)-14 b.26-2(3x) c.6x-28x+10(x+4)-14 d.-6x+26
what brought the greek people together after centuries of fighting over land and trade?
What is 11.1 as a fraction?
Lisa wants to cover the top of the lid in beads. She has enough beads to cover 42 square centimeters. Find the area of the lid. Can Lisa cover the top in beads?
Who established a school in Portugal to help sea captains get better at navigation