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 unthinkable happens and disaster strikes, crippling your network. You implement your disaster plan, but it doesn't go smooth
Degger [83]

Answer:

Post-mortem.

Explanation:

It refer to the discussion or analysis of event like here disaster why it doesn't work like plan based and through whole discussions what we learn so in future avoid such type of issue or mistakes.

7 0
3 years ago
Which of the following is not a characteristic of a good value log entry
Stolb23 [73]
What are we supposed to find? Help us
6 0
2 years ago
Twitter and facebook are both examples of the​ _____________ internet business model.
sweet [91]

community provider  

Provide online meeting place where people with similar interest can communicate and find useful information

People can transact, share interests, photos and videos

3 0
3 years ago
Robert wants to start a mobile app development company that builds apps for both iOS and Android. He is researching different cr
kondaur [170]

Answer: phonegap and xamarin

Explanation:

phonegap and xamarin

6 0
3 years ago
It was stated that the inclusion of the salt in the UNIX password scheme increases the difficulty of guessing by a factor of 409
Furkat [3]

Answer: Explanation:

Salting alters the hash of a password so that it does not physically match the hash of another password. A salt and password are concatenated and processed with a cryptographic hash function. Salt prevents use of rainbow and hash tables to attacking and cracking passwords.

For example, a user has the password, "password000" and is put through a SHA1 hash. In the password database, all of the users with the password "password000" will have the exact same hash, because of the nature of hashing functions.  So, if an attacker breaches the database and brute force the password of the user mentioned above, he could look for all the hashes that match the original user's and would know their passwords are also "password000".

By applying a salt, the password hashes would no longer be identical to one another, even though the actual password is still the same. This requires the attacker to go in and attempt to brute force the second password (which has a different salt), even though it may be the same as the first.

In conclusion, it prevents an attacker from uncovering one password and subsequently uncovering multiple others.

4 0
3 years ago
Other questions:
  • The area that holds all the instructions the computer needs to start up when it is powered on is ________.
    11·1 answer
  • The two types of objects responsible for collecting data are
    14·1 answer
  • Write a program to solve the selection problem. Let k = N/2. Draw a table showing the running time of your program for various v
    12·1 answer
  • Clusters always occur in multiples of what? <br> A.)10 <br> B.)5<br> C.)2 <br> D.)100
    10·2 answers
  • The command-line interface tells a user that it's ready to receive commands by displaying a specific set of characters called a(
    12·1 answer
  • File:///media/fuse/drivefs-0142e6928396ed2afff070ead0fbbbcd/root/JerooLessonFourLabA_1.pdf
    6·1 answer
  • What are TWO examples of soft skills?
    11·1 answer
  • Define a function below, filter_out_strs, which takes a single argument of type list. Complete the function so that it returns a
    10·1 answer
  • Data type can only be true or false <br><br> Answer: Bool
    15·1 answer
  • How do you handle sensitive data?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!