-1

I have 2 separate functions in my code. One is def main and one is def calculations. Here is my code for def calculations:

def calculations(p1x, p1y, p2x, p2y):
    length = p2y - p1y
    width = p2x - p1x
    area = length * width
    perim = 2 * length + width
    return area
    return perim

Then when I try to call it in main later here:

area, perim = calculations(p1x, p1y, p2x, p2y)

I get the error

TypeError: 'float' object is not iterable.

Falko
  • 17,076
  • 13
  • 60
  • 105

1 Answers1

1

You return only one value, area. The other return statement is never reached, because the function is done when the first return statement is reached.

Return both as a tuple instead:

return area, perim
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343