Question
1)) The following function is supposed to compute and display the value of n-factorial for integers greater than 0. def factorial(n): result = 1 for
1))
The following function is supposed to compute and display the value of n-factorial for integers greater than 0.
def factorial(n): result = 1 for i in range(1, n + 1): result = result * i
What is wrong with this function?
The indenting is wrong. All of the lines should be indented by the same amount. |
The calculation is wrong. The result variable will have something other than n-factorial stored in it. |
The function is missing a line. A print statement must be added at the end of it. |
The function is missing a line. A return statement must be added at the end of it.
2)
|
3)
4)
5) The following function is supposed to compute the area of a triangle and return the area as the function's result.
def triangle_area(base, height): area = base * height / 2 ____________________
What line of code must be placed in the blank to achieve this goal?
print area |
print(area) |
return area |
return triangleArea |
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