# Module 5.3 step 5

I am stuck with this issue, can anyone help me understand what I am doing wrong?

# compute and return the area of a rectangle with the passed in length and width

def area(length, width):
area = length * width
perimeter = 2 * (length + width)
return area, perimeter

result = area(10, 4)
print(result)

# compute and return the perimeter of a rectangle with the passed in length and width

def perimeter(length, width):
area = length * width
perimeter = 1 * (length + width)
return area, perimeter

result = area(8, 8)
print(result)

print(â€śThe area of this rectangle isâ€ť, area(10, 4), â€śsquare feet.â€ť)
print(â€śThe perimeter of this rectangle isâ€ť, perimeter(10, 4), â€śfeet.â€ť)
print(â€śThe area of this square isâ€ť, area(8, 8), â€śsquare feet.â€ť)
print(â€śThe perimeter of this square isâ€ť, perimeter(8, 8), â€śfeet.â€ť)

Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux

(40, 28)
(64, 32)
The area of this rectangle is (40, 28) square feet.
The perimeter of this rectangle is (40, 28) feet.
The area of this square is (64, 32) square feet.
The perimeter of this square is (64, 32) feet.

I need this result instead: The area of this rectangle is 40 square feet.
The perimeter of this rectangle is 28 feet.
The area of this square is 64 square feet.
The perimeter of this square is 32 feet.

Check your equation for perimeter. Does 1 * (length + width) really reach all the way around a square or rectangle?

There are a number of things that could be addressed here:

1. Typically you will want to name your functions using action words because they perform an action in your program (and that makes it easier for you and a reader to understand). So, consider get_area and get_perimeter as the names for your functions

2. A function should only do ONE thing, and return ONE value (for now). So, get_area should only find the area using the value of the side(s) you pass to it, and get_perimeter should only find the perimeter using the value of the side(s) you pass to it. Each of them would only return one value.

3. Your function calls are not clear. The first result line (40, 28) shows that your area function worked properly. The second line is correct as well because you called area again, not perimeter.

4. Your final block of output is actually correct in terms of how youâ€™ve coded your program (except, as noted by @mystified13 above, 1 * (length * width) will not return a perimeter). Because you return two values from your function, the two values are returned as a tuple (a type of collection, not a single primitive such as an int or a float) and that is WAY beyond the scope of this module!!!

5. Keep this simple! Define two functions: one to do ONLY area, and one to do ONLY perimeter. When you need area, call the get_are function and return ONLY that value; when you need a perimeter, call get_perimeter and return ONLY that value.

Work on that and see if it will resolve your difficulties. Check back if you are still having problems, and Donâ€™t.Give.Up.

1 Like

That was an oversite error I actually had 2 which give me the result below.

Thanks so much for the explanation, I actually understand the function a little more after reading this. I will rewrite the code and see how it works. Thanks again, I really appreciate the help.

1 Like

Yep, no worries. You can do this!