WeCodeAcademy

Step 3: Summarise: totals and regions

Now answer the first questions: total revenue, units, the average order, and revenue by region. Group with a dictionary: for each sale, add its revenue to the entry for its region. Then sort the regions from best to worst.

Examplepython
Open in editor »

You should see that North earns the most. The format spec {revenue:>8.2f} means: right-aligned, 8 characters wide, 2 decimals, which makes the columns line up.

Your turn: write the code

Given the list of (region, revenue) pairs, build a dictionary of total revenue per region and print the total for "North" and for "South".

Quick check

How does the code add revenue to a region it has not seen yet?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.