Question

Define the function choco(n) to solve the following problem: A company packages and sells boxes with...

Define the function choco(n) to solve the following problem:

A company packages and sells boxes with chocolates. The boxes come in two sizes: large and small. The “large” box contains 48 chocolates and the “small” box contains 8 chocolates. The company makes the most gain by selling large boxes: CDN$26 each. Small boxes produce less gain but still some: a small box provides the company CDN$4 gain. On the other hand, the company loses CDN$ 2 per chocolate not used. Thus, the company will attempt to package as many large boxes as possible, and then as many small boxes as possible.

This function receives as input in the parameter variable a number of chocolates available and it should return a string with the following information: first, the number of large boxes to package, followed by two dots ("..") followed by the number of small boxes to package, followed again by two dots, followed by the number of unpackaged chocolates , followed by two dots and finally the money the company makes, considering the gains (because of the boxes packaged) minus the losses (because of the unused chocolates).

For example, calling this function as choco(503) should return '10..2..7..254 ', because with 503 chocolates the company can package

- 10 large boxes,

- 2 small boxes

- and there are 7 unused chocolates.

In this example the company makes CDN$ 254, that is,

- CDN$26 * 10 = CDN$ 260 because of the 10 large boxes plus

- CDN$ 4 *2= CDN$ 8 because of the 2 small boxes

- minus CDN$ 2 * 7 = CDN$6 (because of the seven unused chocolates).

Notice that the company may have a net loss, when there are not enough chocolates to create any package.

For example:
choco(7) should return '0..0..7..-14'

As an example, the following code fragment:

print (choco(503))

should produce the output:

10..2..7..254

python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:-

def choco(n): #function
largecount=0
smallcount=0
while(True): #loop
if n>=48: #if n is greater than or equal to 48
largecount+=1 #increment count
n=n-48 #decreasing n value
elif n>=8: #if n is greater than or equal to 8
smallcount+=1 #increment count
n=n-8 #decreasing n value
else:
break #breaking the loop
unused=n #unused is remaining n value
net = 26*largecount + 4*smallcount - 2*unused #calculating net value
out=str(largecount)+".."+str(smallcount)+".."+str(unused)+".."+str(net) #format
return out #return string out
n=int(input("Enter n: "))
print(choco(n)) #calling function
  

Screenshot:-

Output:-

Add a comment
Know the answer?
Add Answer to:
Define the function choco(n) to solve the following problem: A company packages and sells boxes with...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Model rocket engines (or motors) are generally purchases in boxes of 24 or packages of...

    C++ Model rocket engines (or motors) are generally purchases in boxes of 24 or packages of 3. If I want 32 engines I would need to purchase 1 box of 24 and 3 packages of 3 (I would end up with 1 extra engine). Write a program that calculates how many boxes and packages you must purchase to get a specific number of engines. Also enter the price of a box and a package and calculate the total cost of...

  • You are consulting for a trucking company that does a large amount of business shipping packages...

    You are consulting for a trucking company that does a large amount of business shipping packages between New York and Boston. The volume is high enough that they have to send a number of trucks each day between the two locations. Trucks have a fixed limit w on the maximum amount of weight they are allowed to carry. Boxes arrive at the New York station one by one, and each package i has a weight wi. The trucking station is...

  • C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for...

    C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for shipping subject to the following restrictions: Shipping requirements The package weight must not exceed 50 pounds. The package must not exceed 3 feet in length, width, or height. The girth of the package must not exceed 5 feet. The girth is the circumference around the two smallest sides of the package. If side1, side2, and side3 are the lengths of the three sides, and...

  • Decision Making 1.- Sunshine Fruit Company sells oranges and other citrus fruits by mail order. Protecting...

    Decision Making 1.- Sunshine Fruit Company sells oranges and other citrus fruits by mail order. Protecting the fruit during shipping is important so the company has designed and produces shipping boxes. The annual cost to make 80,000 boxes is • Materials: $112,000 • Labor: $20,000 (Foced) • Variable Overhead: $60,000 • Fixed Overhead: $16.000 Therefore, the cost per box averages $2.60 Weyer Inc. submits a bid to supply Sunshine Fruit Company with boxes for $2.10 per box Sunshine must give...

  • Sarah Drogo, president of Storage, Inc. a company that makes a wide variety of storage boxes...

    Sarah Drogo, president of Storage, Inc. a company that makes a wide variety of storage boxes for home and office use, is thinking about adding a new line of small plastic storage boxes. This would require a new technology. The company currently uses predominantly cardboard of various weights that are used in its other products. Since this is a big move for the company, Sarah wants to make sure that all of the financial and nonfinancial implications are understood before...

  • Define the functions in Python 3.8 1. Write a function most frequent n that takes a...

    Define the functions in Python 3.8 1. Write a function most frequent n that takes a list of strings and an integer n, and that returns a dictionary where the keys are the top n most frequent unique words in the list, and the values are the frequency of each word: For example, most frequent n(text, 3) should return the dictionary {'is': 2, "the’: 3, 'of': 2}, and most frequent n(text, 2) could return either {'is': 2, 'the’: 3} or...

  • Python Language 3. Shipping Charges The Fast Freight Shipping Company charges the following rates (per 500...

    Python Language 3. Shipping Charges The Fast Freight Shipping Company charges the following rates (per 500 miles shipped): 1. Number Guessing Game Write a program for players to guess the number that the program randomly generated. Your program should randomly generate an integer between 1 and 10. After a player guessing a number, your program should display "Too small", "Too large", or "That's it!". Weight of Package (in Kilograms) 2 kg or less Over 2 kg but not more than...

  • Problem 12-23 Make or Buy Decision (LO12-3] Silven Industries, which manufactures and sells a highly successful...

    Problem 12-23 Make or Buy Decision (LO12-3] Silven Industries, which manufactures and sells a highly successful line of summer lotions and Insect repellents, has decided to diversify in order to stabilize sales throughout the year. A natural area for the company to consider is the production of winter lotions and creams to prevent dry and chapped skin. After considerable research, a winter products line has been developed. However, Silven's president has decided to introduce only one of the new products...

  • Problem 12-23 Make or Buy Decision [LO12-3] Silven Industries, which manufactures and sells a highly successful...

    Problem 12-23 Make or Buy Decision [LO12-3] Silven Industries, which manufactures and sells a highly successful line of summer lotions and insect repellents, has decided to diversify in order to stabilize sales throughout the year. A natural area for the company to consider is the production of winter lotions and creams to prevent dry and chapped skin. After considerable research, a winter products line has been developed. However, Silven's president has decided to introduce only one of the new products...

  • Problem 12-23 Make or Buy Decision [LO12-3] Silven Industries, which manufactures and sells a highly successful...

    Problem 12-23 Make or Buy Decision [LO12-3] Silven Industries, which manufactures and sells a highly successful line of summer lotions and insect repellents, has decided to diversify in order to stabilize sales throughout the year. A natural area for the company to consider is the production of winter lotions and creams to prevent dry and chapped skin After considerable research, a winter products line has been developed. However, Silven's president has decided to introduce only one of the new products...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT