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]
3 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]3 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
Rebecca is an interior designer. What is her job role? need this asap
Solnce55 [7]
B. to decorate and renovate homes
5 0
3 years ago
What is the term for the action of Brazil imposing tariffs on US imports in response to the imposed tariffs by the U.S. on Brazi
TEA [102]

I think the answer is B.

3 0
3 years ago
I am not a living being, I am a cylindrical shape that has three to eight sides. I never die. I can build anything again. What i
Setler79 [48]

Answer:

A shape

Explanation:

4 0
3 years ago
Write Python statements that correspond to the actions below and execute them (a) Assign integer value 3 to variable a. (b) Assi
snow_tiger [21]

Here is code in Python.

#integer value 3 assigned to variable a.

a=3

#integer value 4 assigned to variable v.

b=4

# the value of given expression a * a b *b will be assign to variable c .

c=(a*a)*(b*b)

Explanation:

First an integer value is assigned to variable "a".And then integer 4 is assigned to variable "b". Calculate the value of expression a*ab*b and assigned to variable "c". Here expression a*ab*b can also be written as (a*a)*(b*b).

5 0
3 years ago
Specify either "Write Through" or "Write Back" as the policy which best corresponds to each of the conditions below.
Mariulka [41]

Answer:

1. Write through

2. Write back

3. Write back

4. Write through.

Explanation:

The answers are given accordingly as above.

4 0
4 years ago
Other questions:
  • Read the sentence from the first paragraph of Silent
    6·2 answers
  • Clep allows students to do all of thw following except which?
    9·2 answers
  • __________bits equal one byte.EightTenSixty-fourThirty-twoSix
    10·1 answer
  • What is entered into a cell that is typically numeric and can be used for calculations?
    9·2 answers
  • I have a question. This question will probably be deleted, but why do moderators keep deleting my answers when they are legitima
    13·1 answer
  • Of the following choices what was the best thing to do with electronic equipment you no longer want
    7·1 answer
  • 29. Write a program that asks to input any ten numbers and displays sum of them​
    11·1 answer
  • What does a good résumé help you do?
    10·1 answer
  • How are the four characteristics of the db approach related to the four functions of a dbms?
    15·1 answer
  • Given the tables PRODUCT (ProductID. Description. Cost) SUPPLIER (Supplier D. ContactName, Phone Number) as shown in the figure
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!