Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Exercise: The Factorial!

Sumit Rawal answered on May 16, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • factorial program
  • Program for factorial of a number
  • program to calculate factorial of a number
  • Program for factorial of a number
  • Factorialize a Number
  • find a factorial of a number
  • How to get a factorial number
  • Program for factorial of a number
  • Solution Review: The Factorial!
  • Exercise: factor smiley#
  • Translation exercise: factor#
  • whats 10 factorial
  • Program for factorial of a number

  • Exercise: The Factorial!

    0

    Problem Statement

    In this challenge, you must implement the factorial() function. It takes an integer as a parameter and calculates its factorial. Python does have a built-in factorial function but you’ll be creating your own for practice.

    The factorial of a number, n, is its product with all the integers between 0 and n.

    svg viewer

    The factorial for 0 and 1 is always 1.

    Sample Input

    n = 5

    Sample Output

    120

    Coding Challenge

    Take some time to understand the logic behind this problem before moving to the implementation. Write an algorithm that handles all cases.

    The input will always be an integer, so you don’t need to worry about that. If the integer is negative, the function always returns -1.

    If you feel stuck, feel free to check out the solution review in the next lesson.

    Good luck! 

    Popularity 1/10 Helpfulness 1/10 Language python
    Source: Grepper
    Tags: python
    Link to this answer
    Share Copy Link
    Contributed on May 16 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.