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
The data structure used for file directory is called
Aleks04 [339]
This is a tough question. I’m not sure if I’ll get it right but I’ll try.

Data structures used for file directories typically have a hierarchical tree structure, referred to as a directory structure. The tree has a root directory, and every file in that system has a unique path.

The simplest method of implementing a directory is to use a linear list of file names with pointers to the data blocks. But another way that you can format a file directory is by using a hash table. With this method, the linear list stores the directory entries, but a hash data structure is also used. The hash table takes a value computed from the file name and return the pointer to the file name any linear list.

So I think it’s C. But I’m not 100% sure.

I hope that helps.
6 0
3 years ago
Which is the most efficient way to include a space after each paragraph
TEA [102]

I think the question is referring to the tab key.

5 0
3 years ago
Read 2 more answers
The viewer of an OLAP report can change its format. Which term implies this capability?
amm1812

Answer:

The answer is "Option D".

Explanation:

OLAP reports stands for Online Analytical Processing reports, These reports provide a platform that behind many application use in Business Intelligence. and other options are incorrect that can be described as follows:

  • In option A, It is used to store the data into the OLAP report, that's why it is not correct.
  • In option B, It is software that is used for analytics data, that's why it is not correct.
  • In option C, It is used for finding index values in the 2D array that's why it is not correct.
3 0
3 years ago
Read 2 more answers
A data mart is the operational database for the company. group of answer choices true false
netineya [11]

The statement 'a data mart is the operational database for the company' is true.

We can define a data mart as a  subject-oriented database that focuses on a particular area in an organization.

It is through data mart that the employees of a company can access data faster. Data mart, functioning as the operational database, helps employees as they do not have to manually add all the data again. Also, any piece of data needed by an employee can easily be accessed through the data mart of the company.

One of the advantages of using data mart is that it eradicates human-made errors which can arise if data is added manually by an employee.

To learn more about data mart, click here:

brainly.com/question/25013185

#SPJ4

8 0
2 years ago
Find prime no using Java
bonufazy [111]

Answer:

Um

Explanation:

I don't understand

4 0
3 years ago
Other questions:
  • 286795991 número pra convidar no tiktok​
    11·2 answers
  • What exactly does the value recorded in a single dimension of a sift keypoint descriptor signify?
    15·1 answer
  • Andreas wants to insert an element into an email that will graphically display the values in a table. Which option should he cho
    6·1 answer
  • Benching system are prohibited in
    5·1 answer
  • 20 POINTS AND BRAINLIEST TO CORRECT ANSWER
    15·2 answers
  • Where does change management play a major role in transforming a client
    11·1 answer
  • Explain the history of computing device of mechanical era
    7·1 answer
  • Which of the following statements about wide area networks are true? Select 3 options.
    11·1 answer
  • Que se encarga de notar lo que pasa alrededor
    8·1 answer
  • What are the three main elements common to all radio ads?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!