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

Swipe to show menu

book
Challenge: Solo Coding Capstone

In this chapter, it's time to challenge your coding abilities. You'll be presented with a task, but this time it's up to you to determine the solution. You can use any syntax and techniques you've learned so far, but it's highly recommended to use loops and conditional statements to make your code flexible and adaptable to different inputs and scenarios.

Task

Swipe to start coding

Evaluate items in an inventory dictionary and print appropriate messages based on their stock levels and pricing.

  • Loop through each item in the inventory dictionary.
  • For each item:
    • If stock is below 30, print that it needs restocking.
    • If stock is above 100, print that it should be sold at the discounted price.
    • If stock is 30 to 100, print that it should be sold at the regular price.

Output Requirements

Use the following template print statements exactly:

  • For restocking:
    f"{item} need restocking."
  • For discounted price:
    f"{item} should be sold at the discounted price of {discounted_price}."
  • For regular price:
    f"{item} should be sold at the regular price of {regular_price}."

Note

Follow the print formats exactly to ensure your solution is accepted.

Requirements checklist

  1. For each item in the inventory, if its stock is less than 30, check that the output contains "{item} need restocking." where {item} is the item's name.
  2. For each item in the inventory, if its stock is greater than 100, check that the output contains "{item} should be sold at the discounted price of {discounted_price}." where {item} is the item's name and {discounted_price} is the correct discounted price from the inventory.
  3. For each item in the inventory, if its stock is between 30 and 100 inclusive, check that the output contains "{item} should be sold at the regular price of {regular_price}." where {item} is the item's name and {regular_price} is the correct regular price from the inventory.
  4. Ensure that all three types of messages (restocking, discounted price, regular price) appear in the output if the inventory contains items in each category.

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Β 8
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: Solo Coding Capstone

In this chapter, it's time to challenge your coding abilities. You'll be presented with a task, but this time it's up to you to determine the solution. You can use any syntax and techniques you've learned so far, but it's highly recommended to use loops and conditional statements to make your code flexible and adaptable to different inputs and scenarios.

Task

Swipe to start coding

Evaluate items in an inventory dictionary and print appropriate messages based on their stock levels and pricing.

  • Loop through each item in the inventory dictionary.
  • For each item:
    • If stock is below 30, print that it needs restocking.
    • If stock is above 100, print that it should be sold at the discounted price.
    • If stock is 30 to 100, print that it should be sold at the regular price.

Output Requirements

Use the following template print statements exactly:

  • For restocking:
    f"{item} need restocking."
  • For discounted price:
    f"{item} should be sold at the discounted price of {discounted_price}."
  • For regular price:
    f"{item} should be sold at the regular price of {regular_price}."

Note

Follow the print formats exactly to ensure your solution is accepted.

Requirements checklist

  1. For each item in the inventory, if its stock is less than 30, check that the output contains "{item} need restocking." where {item} is the item's name.
  2. For each item in the inventory, if its stock is greater than 100, check that the output contains "{item} should be sold at the discounted price of {discounted_price}." where {item} is the item's name and {discounted_price} is the correct discounted price from the inventory.
  3. For each item in the inventory, if its stock is between 30 and 100 inclusive, check that the output contains "{item} should be sold at the regular price of {regular_price}." where {item} is the item's name and {regular_price} is the correct regular price from the inventory.
  4. Ensure that all three types of messages (restocking, discounted price, regular price) appear in the output if the inventory contains items in each category.

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