Question

In: Computer Science

You want to send pumpkins to some of your friends for Halloween! You look up shipping...

You want to send pumpkins to some of your friends for Halloween! You look up shipping policies and find out that there are certain constraints involved when shipping packages. A pumpkin needs to weigh at least a certain amount in order to be eligible for shipping. At the same time, no pumpkin can weigh more than a certain amount due to packing restrictions.

However, you have already purchased a whole lot of pumpkins in varying sizes. You now want to find out which of these pumpkins are eligible for shipping. A pumpkin is eligible for shipping if it weighs at least as much as the minimum required weight, and not more than the maximum permitted shipping weight. You have the weights of all pumpkins in a Python list (let’s call this pumpkin_weights).Define a function get_shippable_pumpkins that takes 3 parameters: a list of numbers named pumpkin_weights, and two floats min_weight, and max_weight. The function should compare each value in the list with the minimum and maximum weights allowed (i.e., min_weight and max_weight), and return a list of pumpkins that are within the weight limits for shipping.

You may assume that the min_weight is always less than or equal to max_weight. In other words, the lower limit of weight will always be less than or equal to the upper limit.

Function Name: get_shippable_pumpkins

Parameter:

pumpkin_weights - A list of floats that represents the weights of pumpkins.

min_weight - Minimum allowed weight for a pumpkin to be shippable (inclusive)

max_weight - Maximum allowed weight for a pumpkin to be shippable (inclusive)

Return: A list of pumpkins that are shippable.

Description:

Create and return shippable pumpkins, given a list of pumpkin weights and a minimum and maximum weight allowed for shipping.

Examples:

pumpkin_weights = [33.0, 36.3, 25.1, 29.4, 31.5]

min_weight = 30.0

max_weight = 34.0

Returns: [33.0, 31.5]

pumpkin_weights = [30.6, 21.1, 35.0]

min_weight = 35.0

max_weight = 35.0

Returns: [35.0]

pumpkin_weights = [16.9, 42.0, 25.5, 24.3, 32.6, 29.1, 30.3, 31.6]

min_weight = 22.5

max_weight = 34.5

Returns: [25.5, 24.3, 32.6, 29.1, 30.3, 31.6]

pumpkin_weights = [33.0, 36.0, 35.5, 33.6, 41.2]

min_weight = 36.9

max_weight = 40.1

Returns: [ ]

It is always a good practice to think about edge cases while writing programs. For example, if you find no pumpkins are eligible for shipping, you should return an empty list. Similarly, if the input list is empty, you should return an empty list again. Observe that if the two limits are identical (as in the second example), we are effectively looking for an exact weight for shipping-eligible pumpkins.


You should not take input from the user for this. While testing your program, you may use your own test cases and pass them to the function by calling the function from the python prompt (lists and strings, loops). For this part of the assignment, we only require the get_shippable_pumpkins function to be written.

Solutions

Expert Solution

Answer:-

Python3 Program

def get_shippable_pumpkins(pumpkin_weights,min_weight,max_weight):
    a=[]
    for i in range(len(pumpkin_weights)):
        if pumpkin_weights[i] >= min_weight and pumpkin_weights[i] <= max_weight:
            a.append(pumpkin_weights[i])
    return (a)

Output with the given test case

If you need any help in understanding, please comment your query.

I tried my best for this question, I hope you upvote my answer.

Thank You


Related Solutions

In some states, hunting licenses are allocated by lottery; if you want a license, you send...
In some states, hunting licenses are allocated by lottery; if you want a license, you send in your name to enter the lottery. If the purpose of the system is to ensure that those who want to hunt the most get a chance to do so, what are the flaws of this system? How would the situation improve if people who won licenses were allowed to sell them to others?
You want to have $45000 to send a child to college in 10 years. Your bank...
You want to have $45000 to send a child to college in 10 years. Your bank offers a college savings account that pays an APR of 4.2% compounded monthly. a. How much would you need to deposit monthly to reach your goal? b. Write the first four lines of the amortization table for this investment.
What are some of the main reasons you may want to look at an actual ratio...
What are some of the main reasons you may want to look at an actual ratio to compare two companies, as opposed to just looking at straight numbers from both companies? Reply
You want to reduce text communication with your corrupt friends in Wall Street. You suggest using...
You want to reduce text communication with your corrupt friends in Wall Street. You suggest using Huffman coding to reduce the number of bits in communication. You look over your previous 100 words of texts. You find the following words and their number of occurrence in parenthesis: SELL (12), BUY (8), MOVE (19), HIDE (42), STOP (2) and WATCH (17). This frequency is consistent over all your messages. (a) What codewords do you recommend for each word? (b) Whit these...
You and 9 of your wealthy friends attend a political fundraiser. You each can donate up...
You and 9 of your wealthy friends attend a political fundraiser. You each can donate up to $1,000,000 to the candidate. Let M be the sum of all 10 donations; it is convenient to write M=Mi+M-i, where Mi is the donation by person i, and M-i is the sum of the donations by the other people. Suppose Adelsoros wants to have as much money as possible be donated. He will still offer to donate $1,000,000 as long as the sum...
You and 9 of your wealthy friends attend a political fundraiser. You each can donate up...
You and 9 of your wealthy friends attend a political fundraiser. You each can donate up to $1,000,000 to the candidate. Let M be the sum of all 10 donations; it is convenient to write M=Mi+M-i, where Mi is the donation by person i, and M-i is the sum of the donations by the other people. Suppose Adelsoros wants to have as much money as possible be donated. He will still offer to donate $1,000,000 as long as the sum...
. In preparation for your Biology midterm, you decide to look up past exams to see...
. In preparation for your Biology midterm, you decide to look up past exams to see what kinds of questions were on it. Let B be the event “a question about bacteria shows up on the exam”, and let M be the event “a question about mitosis shows up on the exam”. From past exams, you know that P(B) = 0.3, P(M) = 0.8, and P(M and B) = 0.4. What is the probability of either/or of these types of...
We still have some room for comment on various financial ratios that you can look up...
We still have some room for comment on various financial ratios that you can look up and explain to us. Please take a look above at the financial ratios that have been covered so far in this discussion and pick a new one, show us its formula, and explain what it tells us about an organization's financial health. However, to add yet another fresh question on this topic... Applying this new knowledge about the various analytical techniques we discussed this...
Think about some of your friends and what you have discovered by visiting their homes. Do...
Think about some of your friends and what you have discovered by visiting their homes. Do they buy different things than you do? If so, why? How might a company distinguish you from them in terms of its targeting? Is it always harder to find new customers than it is to retain old ones or does it depend on the business you're in? Does one-to-one marketing have to be expensive? How can small organizations interact with their customers in a...
Look up the Osmotic Pressure in your blood and discuss why sea water will kill you...
Look up the Osmotic Pressure in your blood and discuss why sea water will kill you if you drink it. (I know that it is more to do with kidneys than blood… but that is too much biology for this worksheet.)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT