Question

In: Computer Science

(Please use Python) Suppose that a company sells five products with product codes p101, p107, p122,...

(Please use Python)

Suppose that a company sells five products with product codes p101, p107, p122, p125, and p126. The company has three warehouses, which are located in St. Louis, Chicago, and Kansas City. The retail value for each of the five products and the inventory for each of the warehouses are stored in dictionaries, as shown below.

Copy the code below into a code cell, and then execute that cell.

prices = {'p101':37.52, 'p117':56.98, 'p122':43.72, 'p125':48.33, 'p126':52.45}

inventory = { 'STL':{'p101':520, 'p117':315, 'p122':117, 'p125':258, 'p126':345}, 'CHI':{'p101':125, 'p117':864, 'p122':231, 'p125':612, 'p126':164}, 'KC' :{'p101':264, 'p117':285, 'p122':772, 'p125':467, 'p126':106} }

We will create a new dictionary named total_inventory that contains 5 key/value pairs. The keys should be product ids and the values should be the total quantity for that product across all three warehouses.

An outline of this process is provided for creating total_inventory is provided below:

1. Create an empty dictionary named total_inventory.

2. Loop over the keys of prices. Note that each key refers to a product id. I recommend using a variable name similar to prod_id for the loop variable. For each iteration of the loop:

a. Set a variable named quantity equal to 0.

b. Loop over the values of the elements stored in inventory. Note that these values are themselves dictionaries, and that they store the inventories for each site. For each such site inventory, use the current product id form the outer loop to extract the quantity of that product at the current site. Add this quantity to quantity.

c. Add prod_id / quantity as a new new/value pair in total_inventory.

Display the results by looping over the key/value pairs in total_inventory. Each time the loop executes, print out the pair in the following format: key: value

We will now calculate the total value of the company’s inventory.

Create a new code cell to perform the following steps:

1. Set total_value equal to 0.

2. Loop over the keys (product ids) stored in prices. Each time the loop executes:

a. Use the current product id to extract the associated values from the dictionaries prices and total_inventory.

b. Multiply these values found in Part a together and add the result to total_value.

Print the result with a message as follows:

The total value of the inventory is $xxxx.

Solutions

Expert Solution

Thanks for the question.

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. 


If you are satisfied with the solution, please rate the answer. 

Thanks!
===========================================================================

prices = {'p101': 37.52, 'p117': 56.98, 'p122': 43.72, 'p125': 48.33, 'p126': 52.45}

inventory = {'STL': {'p101': 520, 'p117': 315, 'p122': 117, 'p125': 258, 'p126': 345},
             'CHI': {'p101': 125, 'p117': 864, 'p122': 231, 'p125': 612, 'p126': 164},
             'KC': {'p101': 264, 'p117': 285, 'p122': 772, 'p125': 467, 'p126': 106}}

# 1. Create an empty dictionary named total_inventory.
total_inventory = {}
# 2. Loop over the keys of prices. Note that each key refers to a product id.
for key in prices.keys():
    # a. Set a variable named quantity equal to 0.
    quantity = 0
    # b. Loop over the values of the elements stored in inventory.
    for quant in inventory.values():
        quantity += quant.get(key)

    # c. Add prod_id / quantity as a new new/value pair in total_inventory.
    total_inventory[key] = quantity
    # Each time the loop executes, print out the pair
    print(f'{key}:{quantity}')
# Create a new code cell to perform the following steps:
# 1. Set total_value equal to 0.
total_value = 0
# 2. Loop over the keys (product ids) stored in prices.
for key, price in prices.items():
    # xtract the associated values from the dictionaries prices and total_inventory.
    quantity = total_inventory.get(key)
    total_value += price * quantity
# Print the result with a message as follows:
# The total value of the inventory is $xxxx.
print(f'The total value of the inventory is ${total_value}')

==========================================================================


Related Solutions

Please use the python and explain. Also please show python. Suppose that a cashier owes a...
Please use the python and explain. Also please show python. Suppose that a cashier owes a customer some change and that the cashier only has quarters, dimes, nickels, and pennies. Write a program the computes the minimum number of coins that the cashier can return. To solve this problem use the greedy algorithm explained below. PROBLEM STATEMENT: Your program should first ask the user for the amount of money he/she is owed (in dollars). You may assume that the user...
Problem 2: Universal Product Codes(UPCs) Retail products are identified by their Universal Product Codes (UPCs). The...
Problem 2: Universal Product Codes(UPCs) Retail products are identified by their Universal Product Codes (UPCs). The most common form of a UPC has 12 decimal digits: The first digit identifies the product category, the next five digits identify the manufacturer, the following five identify the particular product, and the last digit is a check digit. The check digit is determined in the following way: • Beginning with the first digit multiply every second digit by 3. • Sum all the...
Twin Products Company produces and sells two products. Product M sells for $12 and has variable...
Twin Products Company produces and sells two products. Product M sells for $12 and has variable costs of $6. Product W sells for $15 and has variable costs of $10. Twin predicted sales of 25,000 units of M and 20,000 of W. Fixed costs are $60,000 per month. Assume that Twin achieved its sales goal of $600,000 for September, but fell short of its expected operating income of $190,000. Which of the following descriptions best describes the actual results reported...
A company sells two products, Product A and Product B. Assume that the variable costs for...
A company sells two products, Product A and Product B. Assume that the variable costs for each product are $7. In a particular market, men and women value the two products as follows: Value to the Customer Product A Product B Men (50 % of market) $ 12 $ 15 Women (50 % of market) $ 14 $ 11 If management is considering offering a bundle containing both products, what is the maximum price that could be charged for this...
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to...
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to print the type of the following variables. Please write down the codes and the output as well. x = 3.5 y = '3.5' z = {1:'John', 2:'Wick', 3:'Barry', 4:'Allen'}
Reliable Supply Company sells only two products, Product A and Product B. Product A Product B...
Reliable Supply Company sells only two products, Product A and Product B. Product A Product B Total Selling price $35 $58 Variable cost per unit $27 $42 Total fixed costs $395,000 Reliable Supply sells 4 units of Product A for each 3 units it sells of Product B. Reliable Supply has a tax rate of 20%. Required: a.   What is the breakeven point in units for each product, assuming the sales mix is 4 units of Product A for each...
ABC Company sells Product A, Product B, and Product C. Data regarding these products are presented...
ABC Company sells Product A, Product B, and Product C. Data regarding these products are presented below Products Selling price per unit Variable cost per unit Sales mix A 120 80 4 B 200 150 3 C 90 40 3 Fixed Cost 1,150,000 Requirement: Compute for BEP in units and peso, provide the composition.
A company sells only two products, Product A and Product B, and has the following cost...
A company sells only two products, Product A and Product B, and has the following cost information: Selling price per unit – Product A                  $4 Selling price per unit – Product B                  $5 Variable cost per unit – Product A                 $2 Variable cost per unit – Product B                 $3 Total fixed costs                                                $840 The company sells two units of Product A for each unit it sells of Product B. The company faces an income tax rate of 30%. A) What is the breakeven point in...
A company sells two products, A and B. Product A Product B Produced and sold 8.000...
A company sells two products, A and B. Product A Product B Produced and sold 8.000 units 16.000 units Sale price per unit 65 52 Variable cost per unit 35 30 Fixed cost per unit 15 15 Fixed cost is divided in a traditional way, based on the produced quantity. The company started to design a new product C to replace product B. The company could sell 11.000 units of product C with a selling price of 80 per unit....
A company manufactures and sells two products: Product A1 and Product C4. Data concerning the expected...
A company manufactures and sells two products: Product A1 and Product C4. Data concerning the expected production of each product and the expected total direct labor-hours (DLHs) required to produce that output appear below: Expected Production Direct Labor-Hours Per Unit Total Direct Labor-Hours Product A1 300 4.0 1,200 Product C4 600 2.0 1,200 Total direct labor-hours 2,400 The direct labor rate is $25.90 per DLH. The direct materials cost per unit is $285 for Product A1 and $244 for Product...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT