-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.

1
  • Float objects aren't iterable in anyone's code. return perim is never actually reached. Commented Nov 22, 2015 at 21:12

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.