Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Sales and Shipments | Loops
Introduction to Python (generated task tests)

Swipe to show menu

book
Challenge: Sales and Shipments

In this challenge, you'll manage the daily stock levels of essential grocery store products over a week. By utilizing the range() function in conjunction with the len() function, you'll simulate sales impacts on inventory.

Task

Swipe to start coding

Update product stock levels based on sales and shipments using loops.

  • Use a for loop with index iteration to go through the products list.
    • For each product subtract the number of units sold (units_sold) from the products stock.
  • Use a second for loop (also with index iteration) to go through products again.
    • Add the corresponding value from shipment_received to update the stock.

Output Requirements

  • After processing sales, print:
    Stock after sales for <product_name>: <stock_level> units
  • After processing shipments, print:
    Stock after shipment for <product_name>: <stock_level> units
  • At the end, print:
    Final stock levels for all products: <products>

Requirements checklist

  1. After processing sales, for each product, check that the printed stock level matches the initial stock minus the corresponding units sold.
  2. After processing shipments, for each product, check that the printed stock level matches the stock after sales plus the corresponding shipment received.
  3. At the end, check that the printed final stock levels for all products match the initial stock minus units sold plus shipment received for each product.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 5
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

Awesome!

Completion rate improved to 2.17

book
Challenge: Sales and Shipments

In this challenge, you'll manage the daily stock levels of essential grocery store products over a week. By utilizing the range() function in conjunction with the len() function, you'll simulate sales impacts on inventory.

Task

Swipe to start coding

Update product stock levels based on sales and shipments using loops.

  • Use a for loop with index iteration to go through the products list.
    • For each product subtract the number of units sold (units_sold) from the products stock.
  • Use a second for loop (also with index iteration) to go through products again.
    • Add the corresponding value from shipment_received to update the stock.

Output Requirements

  • After processing sales, print:
    Stock after sales for <product_name>: <stock_level> units
  • After processing shipments, print:
    Stock after shipment for <product_name>: <stock_level> units
  • At the end, print:
    Final stock levels for all products: <products>

Requirements checklist

  1. After processing sales, for each product, check that the printed stock level matches the initial stock minus the corresponding units sold.
  2. After processing shipments, for each product, check that the printed stock level matches the stock after sales plus the corresponding shipment received.
  3. At the end, check that the printed final stock levels for all products match the initial stock minus units sold plus shipment received for each product.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

close

Awesome!

Completion rate improved to 2.17

Swipe to show menu

some-alt