Question: A Python program managing a school vending machine keeps the current inventory in a list variable called inventory with tuples (product_str, stock_int, sold_int, price_float). product_str

A Python program managing a school vending machine keeps the current inventory in a list variable called inventory with tuples (product_str, stock_int, sold_int, price_float). product_str is the name of the product; stock_int is the quantity still in stock (an int), sold_int is the quantity sold (int), and price_float is the sell price -- a float number. For example, the inventory list at some time may look like this:

[('Snickers Bar', 20, 30, 1.5), ('Tic Tac', 18, 10, 1.0), ('Cheetos', 43, 15, 2.0)] 

a) Write ONE expression with a list comprehension that returns a list with the total sales $$ amount for each product. Name the returned list sales_lst. The total sale for a product tuple is sold_int*price_float. For the example inventory list above, the desired list with product sales is:

[('Snickers Bar', 45.0), ('Tic Tac', 10.0), ('Cheetos', 30.0)] 

b) Write ONE expression that uses sales_lst from part a) with a list comprehension that returns the total sales across all products. For the products in the above example, the total sales figure is 85.0.

Hint: use the builtin sum() function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!