Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Product Revenues Capstone | Functions
Introduction to Python (copy)

Stryg for at vise menuen

book
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.

Opgave

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 prices and quantities_sold;
    • Store the results in a list called revenue and return it.
  • 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.
  • Use calculate_revenue() to generate the revenue list.

  • Use zip() to combine product_names and revenue into a list of tuples called revenue_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

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 6. Kapitel 7
Vi beklager, at noget gik galt. Hvad skete der?

Spørg AI

expand
ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

book
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.

Opgave

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 prices and quantities_sold;
    • Store the results in a list called revenue and return it.
  • 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.
  • Use calculate_revenue() to generate the revenue list.

  • Use zip() to combine product_names and revenue into a list of tuples called revenue_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

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 6. Kapitel 7
Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Vi beklager, at noget gik galt. Hvad skete der?
some-alt