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
Describe some common types of charts.​
Mekhanik [1.2K]
Bar chart.
Pie chart.
Line chart.
4 0
2 years ago
Read 2 more answers
In a mobile phone network, how many times as strong would
steposvetlana [31]

Answer:

how many times as strong would what?

put your question in the replies to this answer and I'll gladly answer it

Explanation:

May I have brainliest please? :)

6 0
2 years ago
Mattias's friend asked him to critique his presentation about gorillas. Mattias noticed that there weren't any images of gorilla
Deffense [45]

Answer:

c

Explanation:

7 0
3 years ago
What do you think is the most important factor affecting the collection of digital data and what impact do you think that this f
borishaifa [10]

<u>Answer:</u>

<u>Privacy concerns.</u>

<u>Explanation:</u>

Privacy concerns have played an important role in how we collect digital data. For example, privacy activists believe that an individual has the right to know how his or her information is being used and that such an individual also has the right to withhold such information.

Such issues have affected the ability of law enforcement agencies to investigate criminal activities. For example, an individual who is accused of a crime may claim a <em>right to withhold his personal information, such as his mobile device, and thus he refuses to give out such information.</em>

4 0
3 years ago
1. It defines the amount of white space that appears at the top, bottom, left, and right edge of
LekaFEV [45]

Answer:

Margin is the correct answer to the given question .

Explanation:

The main objective of the margin is to setting the white space that are showing up at the top , bottom, left and the right corners of the file or the document .

Following are steps to setting the white space that are showing up at the top , bottom, left and the right corners of the file or the document

  • Firstly click on the page layout  options  .
  • After that click on the margin tab .In this tab you will given the the top, bottom, left, and right margin according to your need
  • Finally click on ok to finish them .
8 0
3 years ago
Other questions:
  • Suppose you want to delete an existing file from within Word. What would you do? A. Click on the File button, choose Recent, ope
    9·1 answer
  • Each peripheral device has its own software, called a(n) ____, which contains the detailed instructions required to start that d
    6·1 answer
  • Illustrate the process of using an operating system to manipulate a computer’s desktop, files and disks.
    12·1 answer
  • A bookmarking site is a website that enables members to manage and share media such as photos, videos, and music. true or false
    14·1 answer
  • Serveral cheetas are growling at each other while hunting for animals.for which need are they competing?
    14·1 answer
  • 6 external parts of computer
    10·2 answers
  • Review the portion of the application above. Record any changes or corrections that need to be made and why.
    13·1 answer
  • Select one or more of the following: Which of these events will cause signal(s) to be generated by the kernel (the operating sys
    6·1 answer
  • At the start of the school year, Brianna’s history teacher announces that students’ final grades will be weighted based on how t
    8·2 answers
  • Everyone within a company needs to be aware of what data can do to improve business processes and how to make it happen. Which c
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!