Question

Given an integer named area which represents the area of a rectangle, write a function minPerimeter...

  1. Given an integer named area which represents the area of a rectangle, write a function minPerimeter that calculates the minimum possible perimeter of the given rectangle, and prints the perimeter and the side lengths needed to achieve that minimum. The length of the sides of the rectangle are integer numbers.

    For example, given the integer area = 30, possible perimeters and side-lengths are:

    (1, 30), with a perimeter of 62 (2, 15), with a perimeter of 34 (3, 10), with a perimeter of 26 (5, 6), with a perimeter of 22

    Thus, your function should print only the last line, since that is the minimum perimeter.

  2. A python program

Homework Answers

Answer #1

The below code that helps give you the desired result and it will give you the result of a rectangle only(i.e a and b are not equal )

import math;
def minperimeter(n):
a,b,p,m=0,0,0,1000000;
for i in range(1,math.floor(math.sqrt(n))):
if n%i==0:
p=2*(i+(n//i));
if p<m:
m=p;
a=i;
b=n//i;
print("(%d,%d),with a perimeter of %d"%(a,b,m));
n=int(input());
minperimeter(n);

*********************************************************************************************************************************

The below code will give the results of rectangles which also includes square(i.e rectangle which all sides are equal)

import math;
def minperimeter(n):
a,b,p,m=0,0,0,1000000;
for i in range(1,math.floor(math.sqrt(n))+1):
if n%i==0:
p=2*(i+(n//i));
if p<m:
m=p;
a=i;
b=n//i;
print("(%d,%d),with a perimeter of %d"%(a,b,m));
n=int(input());
minperimeter(n);

Both the programs have only a minor change that is +1 in the second program of range function in for loop.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
MATHEMATICS 1. The measure of location which is the most likely to be influenced by extreme...
MATHEMATICS 1. The measure of location which is the most likely to be influenced by extreme values in the data set is the a. range b. median c. mode d. mean 2. If two events are independent, then a. they must be mutually exclusive b. the sum of their probabilities must be equal to one c. their intersection must be zero d. None of these alternatives is correct. any value between 0 to 1 3. Two events, A and B,...
Please summarize the below article in approximately 100 words: Monumental function in British Neolithic burial practices...
Please summarize the below article in approximately 100 words: Monumental function in British Neolithic burial practices Ian Kinnes The high-risk rate of survival for the non-megalithic series of Neolithic funerary monuments, recently re-emphasized by Piggott (1973: 34), introduces a further variable into the deductive study of burial practices. In Britain and Europe the overall distribution of monumental forms present both lacunae and a marked preponderance of cairns over earthen mounds which are in ill accord with the known or predicted...
      MK Restaurant: Branding of Thai-Style Hotpot The restaurant industry is one of the most...
      MK Restaurant: Branding of Thai-Style Hotpot The restaurant industry is one of the most competitive in Thailand. With a large number of players ranging from restaurants in five-star hotels, global fast-food chains to small stalls along the streets and everything in between, the Thais are spoiled for choice. In addition, as the world becomes globalized, consumers are familiar with international dishes and would not hesitate to try new offerings from the other side of the globe. As a...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...