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
What is NOT an issue associated with tag management systems? There is no automation available for tag management systems. Managi
SSSSS [86.1K]

Answer:

Managing tags means experience with the programming language to utilize them.

Explanation:

In different markets, tags are used to assigned prices and values to different products. To make these tags "tag management systems" are deployed to manage and create these tags.

Tag management system is software, that is used to create the tags with ease. There is no need of coding or programming while creating tags.

<em>So we can say that, There is no issue of Managing tags means experience with the programming language to utilize them.</em>

5 0
3 years ago
Which algorithm makes the most efficient use ofmemory?
SashulF [63]

Answer:

Best-fit Algorithm

Explanation:

Best-fit: Allocating the smallest memory location that is greater than or equal to the size of process.

<u>Example</u>

Let these are the memory locations-210kb,310kb,260kb,610kb

                    and size of processes-160kb,450kb,250kb,300kb

For the first-fit,

We allocate 160 kb to the 210kb memory location

Then, we allocate 450 kb to the 610kb because others don't have the size.

Then,we allocate 250kb to the 310 kb.

300 kb will stop,as no memory locations can execute.

For the Best-fit,

We allocate 160 kb to the 210kb memory location

Then,we allocate 450kb to the 610kb.

Then,we allocate 250kb to the  260kb not 310kb according to best-fit.

Then we allocate 300kb to the 310kb.

For the worst fit,

We allocate 160 kb to the 610kb memory location according to the worst-fit algorithm.

Then,we can't allocate 450kb to any memory location.

Then,we allocate 250kb to the 310kb .

We can' allocate 300kb in 260kb memory location.

As we can see from this example that in First-fit algorithm 300kb process will stop as no memory location is there.

In worst-fit algorithm ,We can't allocate 450kb,300kb to any memory locations.

In Best-fit algorithm,we can allocate the process to each location,so this algorithm is using memory in a efficient way.    

5 0
3 years ago
Mary, Tim, John, and Jenn each sold three million dollars worth of product within six months. Each month one of them was awarded
photoshop1234 [79]

if its the same chart im looking at on this page, the answer is john.

5 0
3 years ago
Read 2 more answers
Explain why the computer is powerful working tool???​
notsponge [240]

Answer:

here ya go

Explanation:

A computer is a powerful tool because it is able to perform the information processing cycle operations (input, process, output, and storage) with amazing speed, reliability, and accuracy; store huge amounts of data and information; and communicate with other computers.

8 0
2 years ago
Which technology will a business use to identify unauthorized access to intranet sites or files by its employees?
monitta

Answer:

Computer Forensics

Explanation:

Your Welcome....

8 0
2 years ago
Other questions:
  • You are given a string of n characters s[1 : : : n], which you believe to be a corrupted text document in which all punctuation
    12·1 answer
  • Designing the moving parts of a car—including the engine, drivetrain, steering, and brakes—is done by what type of engineer?
    11·2 answers
  • What two terms below describe a network device with three ports, two of which send and receive all traffic, and the third port m
    6·1 answer
  • When an architect designs a building, what visual design elements could be used to help capture a viewer’s attention? A) The use
    5·2 answers
  • How do open online courses help with independent learning? (1 point)
    13·2 answers
  • What are the two types of formulas in excel
    9·1 answer
  • ​Suppose your computer network was compromised in a large scale virus attack last Thursday. Most of the data files got corrupted
    8·1 answer
  • Your organization network diagram is shown in the figure below. Your company has the class C address range of 199.11.33.0. You n
    8·1 answer
  • The add_prices function returns the total price of all of the groceries in the dictionary. Fill in the blanks to complete this f
    15·1 answer
  • Write an algorithm to show whether a given number is even or odd.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!