A chef needs to buy red and green peppers. He can buy from 3 vendors. Vendor 1 s
ID: 3676087 • Letter: A
Question
A chef needs to buy red and green peppers. He can buy from 3 vendors. Vendor 1 sells a box of 20 red peppers and 10 green peppers for $60. Vendor 2 sells a box of 10 red peppers and 10 green peppers for $40. Vendor 3 sells a box of 10 red peppers and 20 green peppers for $50. The restaurant needs 350 red peppers and 400 green peppers. Using Python, I would like to know a) How many boxes should he buy from each vendor in order to minimize cost and b) the minimum cost. Please let me know which Python version you are using to compute it.
Please show all steps, using basic packages over advanced functions when possible. Thanks!
Explanation / Answer
#initial values
v1 = 0
v2 = 0
v3 = 0
minCost = 100000000
# try number of boxes from each vendor in range 0-50
for i in range(0, 50):
for j in range(0, 50):
for k in range(0, 50):
# calculate total number of goods
red = 20 * i + 10 * j + 10 * k
green = 10 * i + 10 * j + 20 * k
# check if it satifies given requirement
if red >= 350 and green >= 400:
# calculate cost of current combination
cost = 60 * i + 40 * j + 50 * k
# if cost less than previous minimum
# update the values
if cost < minCost:
minCost = cost
v1 = i
v2 = j
v3 = k
# print the result
print('Boxes from vendor 1: ', v1)
print('Boxes from vendor 2: ', v2)
print('Boxes from vendor 3: ', v3)
print('Minimum cost: ', minCost)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.