Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Product Revenues Capstone | Functions
Introduction to Python
Section 6. Chapter 7
single

single

Challenge: Product Revenues Capstone

Swipe to show menu

Let's put together everything you've learned in this section and apply it.

In this task, your objective is to calculate the total revenue for each product in a grocery store based on their prices and quantities sold.

After calculating the revenues, you will sort the products alphabetically and display the results in a formatted output.

Task

Swipe to start coding

Follow these step-by-step instructions to complete the task:

  1. Define calculate_revenue(prices, quantities_sold):

    • Multiply each price by its matching quantity.
    • Store the results in a revenue list.
    • Return the list.
  2. Call calculate_revenue() to calculate the revenue for each product.

  3. Use zip() to combine products and revenue into a list named revenue_per_product.

  4. Define formatted_output(revenues):

    • Sort the list alphabetically by product name.
    • Print each result in this format:

    <product_name> has total revenue of $<revenue>

  5. Call formatted_output(revenue_per_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 6. Chapter 7
single

single

Ask AI

expand

Ask AI

ChatGPT

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

some-alt