Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Factorial Test Case

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Factorial Test Case. Start with the requirements on the right.

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.

Problem

Commonwealth Fusion Systems software may perform integer calculations related to SPARC operations. Implement a function that calculates the factorial of a non-negative integer, then validate it with representative and boundary-focused test cases.

The factorial of n, written as n!, is the product of every integer from 1 through n. By definition, 0! equals 1.

Formal Specification

Implement factorial(n), where n is an integer from 0 through 12. Return an integer containing n!. Your test coverage must include the smallest valid input, a typical input, and a larger input within the constraints.

Constraints

  • 0 <= n <= 12
  • n is an integer
  • Return an integer
  • Do not use a factorial library function

Function Signature

def factorial(n):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output