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.
Swipe to start coding
Follow these step-by-step instructions to complete the task:
-
Define
calculate_revenue(prices, quantities_sold):- Multiply each price by its matching quantity.
- Store the results in a
revenuelist. - Return the list.
-
Call
calculate_revenue()to calculate the revenue for each product. -
Use
zip()to combineproductsandrevenueinto a list namedrevenue_per_product. -
Define
formatted_output(revenues):- Sort the list alphabetically by product name.
- Print each result in this format:
<product_name> has total revenue of $<revenue> -
Call
formatted_output(revenue_per_product).
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat