1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
serg [7]
2 years ago
11

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

eger 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

Computers and Technology
1 answer:
MrRissso [65]2 years ago
7 0

Hi, you haven't provided the programing language in which you need the code, I'll explain how to do it using Python, and you can follow the same logic to make a program in the programing language that you need.

Answer:

import math

def rectangle(perimeter, area):

   l1_1 = (perimeter+math.sqrt((perimeter**2)-(16*area)))/4

   l1_2 = (perimeter-math.sqrt((perimeter**2)-(16*area)))/4

   l2_1 = area/l1_1

   l2_2 = area/l1_2

   print(l1_1,l2_1)

   print(l1_2,l2_2)

   if l1_1.is_integer() and l2_1.is_integer() and l1_1>0 and l2_1>0:

       return(int(max(l1_1,l2_1)))

   elif l1_2.is_integer() and l2_2.is_integer() and l1_2>0 and l2_2>0:

       return(int(max(l1_2,l2_2)))

   else:

       return(None)

Explanation:

  • We import math to make basic operations
  • We define the rectangle function that receives perimeter and area
  • We calculate one of the sides (l1_1) of the rectangle using the quadratic equation to solve 2h^2 - ph + 2a = 0
  • We calculate the second root of the quadratic equation for the same side (l1_2)
  • We calculate the second side of the rectangle using the first root on w = a/h
  • We calculate the second side of the rectangle using the second root on w= a/h
  • We verify that each component of the first result (l1_1, l2_1) is an integer (using the build-in method .is_integer) and greater than 0, if True we return the maximum value between them (using the max function) as w
  • If the first pair of sides evaluate to False we check the second root of the equation and if they meet the specification we return the max value
  • if all the if statements evaluate to false we return None to indicate that not positive or integer sides were found

You might be interested in
Help me help you............
KiRa [710]

Answer:

change how big or small the shape or sprite is

6 0
1 year ago
How does technology improve productivity at home? (Select all that apply.)
Aliun [14]

Answer:

B, C

Explanation:

?

5 0
3 years ago
(50 points) Write a programthat adds the first and last elements of an integer array and stored as the first element of the outp
Elena L [17]

Answer:

A is the input array

B = [] ; %B is initially an empty array

for i = 1:length(A)/2  %iterates over A until the midpoint of A

   B(i) = A(i) + A(end + 1 - i);  %This adds the numbers from the first half and %second half of A, and stores in B

end

disp(B)

3 0
3 years ago
How to scan documents from printer to computer?
Romashka-Z-Leto [24]
The printer should have a control panel. Then you gotta touch Computer to scan to the computer that is connected. Then, touch the name of the computer that you would like to save the scan to. Lastly, touch<span> the scan-to type that corresponds to the document or photo you are scanning.

(By the way, anytime I said 'touch' it meant touch on control panel I believe)

Hope O helped and I apologize if it did not because I own a Mac with no printer. :)</span>
3 0
3 years ago
Write an algorithm to calculate the simple interest using the formula​
sesenic [268]

Answer:

step 1:- start

step 2:-read principal amount, rate and time

step 3:- calculate interest using formula sI=((amount*rate*time)/100)

step 4:- print simple interest

step 5:- //CPP program to find compound interest for. //given values

3 0
2 years ago
Other questions:
  • That is Entrepreneur ? ?<br>​
    8·1 answer
  • The create_python_script function creates a new python script in the current working directory, adds the line of comments to it
    9·1 answer
  • There are several methods of updating information and data on a webserver. We must consider who performs those updates upfront w
    9·2 answers
  • What is constructive criticism?
    9·1 answer
  • Which of the following declares an abstract method in an abstract C++ class? (Points : 2) public: void print();
    14·1 answer
  • In windows, a(n) ________ follows the file name and a period and indicates the file type.
    9·1 answer
  • A(n) ____________________ is hardware or software that blocks or allows transmission of information packets based on criteria su
    13·1 answer
  • Write any four difference between email and effects​
    14·1 answer
  • | HELP PLS! C++ Sorting arrays can be performed using either Selection Sort or Insertion Sort or
    13·1 answer
  • On his website, Mario has a video that visitors must click to play. He wants the video to play automatically when the page loads
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!