Question
Debug the following program: Def factorial(n): Calculate the factorial of the given value and return the result. The factorial of n is the product of
Debug the following program:
Def factorial(n): """Calculate the factorial of the given value and return the result.
The factorial of n is the product of all positive integers less than or equal to n. This function does not support negative values - if a negative value is given, this function just returns 1.
Arguments: n -- A positive integer """ result = 1 while n != 0: n = n - 1 result = result * n return result
# Calculate factorial for the first four integers for i in range(-1, 5): print('Factorial of', i, 'is', factorial(i)
Expected Output
Factorial of 1 is 1 Factorial of 2 is 2 Factorial of 3 is 6 Factorial of 4 is 24
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started