Challenge: Product Revenues Capstone
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
Calculate and display product revenues using functions, with results presented in a clear, formatted way.
-
Define
calculate_revenue(prices, quantities_sold):- Multiply each pair of elements from
pricesandquantities_sold; - Store the results in a list called
revenueand return it.
- Multiply each pair of elements from
-
Define
formatted_output(revenues):- Accepts a list of tuples:
(product_name, revenue); - Sort the list alphabetically by product name;
- Print each product and its revenue using the specified format.
- Accepts a list of tuples:
-
Use
calculate_revenue()to generate therevenuelist. -
Use
zip()to combineproduct_namesandrevenueinto a list of tuples calledrevenue_per_product. -
Call
formatted_output()to print the sorted results.
Output Requirements
-
For each product, print:
<product_name> has total revenue of $<revenue> -
Ensure products are sorted alphabetically before printing.
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Oppsummer dette kapittelet
Explain code
Explain why doesn't solve task
Fantastisk!
Completion rate forbedret til 2.17
Challenge: Product Revenues Capstone
Sveip for å vise menyen
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
Calculate and display product revenues using functions, with results presented in a clear, formatted way.
-
Define
calculate_revenue(prices, quantities_sold):- Multiply each pair of elements from
pricesandquantities_sold; - Store the results in a list called
revenueand return it.
- Multiply each pair of elements from
-
Define
formatted_output(revenues):- Accepts a list of tuples:
(product_name, revenue); - Sort the list alphabetically by product name;
- Print each product and its revenue using the specified format.
- Accepts a list of tuples:
-
Use
calculate_revenue()to generate therevenuelist. -
Use
zip()to combineproduct_namesandrevenueinto a list of tuples calledrevenue_per_product. -
Call
formatted_output()to print the sorted results.
Output Requirements
-
For each product, print:
<product_name> has total revenue of $<revenue> -
Ensure products are sorted alphabetically before printing.
Løsning
Takk for tilbakemeldingene dine!
single