Menu

(Solved) : 20 Pts Write Function Rectangle Perimeter Area Takes Two Positive Integers Perimeter Area Q44126090 . . .

[20 pts) Write the function rectangle(perimeter, area), which takes two positive integers, perimeter and area. It returns an

[20 pts) Write the function rectangle(perimeter, area), which takes two positive integers, perimeter and area. It returns an integer which is the length of the longest side of a rectangle with integer side lengths w and h which has the given perimeter and area. If no such rectangle exists, it returns None. As a reminder the perimeter of a rectangle with sides w and h is 2w + 2h. The area is w* h. Hint: The built-in function round takes a number as its argument and returns the nearest! integer. For example, round(4.0) returns 4, round(4.3) returns 4, and round(4.7) returns 5. Similarly, to do integer division and get an integer result, discarding any fractional result, there is another operator, //, which performs floor division Example: rectangle(14, 10) will return 5 because a 2 x 5 rectangle 5 is the longest side of a rectangle with perimeter 14 and area 10 rectangle(25, 25) will return None because a 2.5 x 10 rectangle does not have integer side lengths Show transcribed image text [20 pts) Write the function rectangle(perimeter, area), which takes two positive integers, perimeter and area. It returns an integer which is the length of the longest side of a rectangle with integer side lengths w and h which has the given perimeter and area. If no such rectangle exists, it returns None. As a reminder the perimeter of a rectangle with sides w and h is 2w + 2h. The area is w* h. Hint: The built-in function round takes a number as its argument and returns the nearest! integer. For example, round(4.0) returns 4, round(4.3) returns 4, and round(4.7) returns 5. Similarly, to do integer division and get an integer result, discarding any fractional result, there is another operator, //, which performs floor division Example: rectangle(14, 10) will return 5 because a 2 x 5 rectangle 5 is the longest side of a rectangle with perimeter 14 and area 10 rectangle(25, 25) will return None because a 2.5 x 10 rectangle does not have integer side lengths

Expert Answer


Answer to [20 pts) Write the function rectangle(perimeter, area), which takes two positive integers, perimeter and area. It return…

OR