Reputation: 9
Instructions: This function to calculate the area of a rectangle is not very readable. Can you refactor it, and then call the function to calculate the area with base of 5 and height of 6? Tip: a function that calculates the area of a rectangle should probably be called rectangle_area, and if it's receiving base and height, that's what the parameters should be called.
My attempt:
def area_rectangle (base, height):
area_rectangle (5, 6)
area = (base*height)
print("The area is " + str(area))
Error message:
Here is your output:
Not quite. Remember to use meaningful names for functions and variables, and to call the function correctly.
Question: What am I doing incorrectly, to rectify this issue?
Upvotes: 0
Views: 913
Reputation: 71570
I'm pretty sure you meant:
def area_rectangle (base, height):
area = (base * height)
print("The area is " + str(area))
area_rectangle(5, 6)
The reason your code didn't work is because it will become infinite recursion. The function would call itself and call itself infinite times until the RecursionError
comes.
So you would need to call it outside the function.
Upvotes: 2