Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Factorial Function in Python
00:00
5 left

Factorial Function in Python

EasyPython

Problem

Implement the factorial function in Python.

Define factorial(n) to return the product of every integer from 1 through n. The function must use an iterative approach and return 1 for the base case n = 0.

Function Contract

  • Input: a non-negative integer n.
  • Output: the integer value of n!.

Constraints

  • 0 <= n <= 10^4
  • n is an integer
  • The input is non-negative

Function Signature

def factorial(n):
Interviewer

Your question is Factorial Function in Python. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.