Get startedGet started for free

Book genre popularity

Previously, you worked with a dictionary containing information about authors and the number of books that they have written.

In this exercise, data about the same authors has been aggregated to create a new dictionary called genre_sales, where the keys are the genre and the values are the average sales for that genre among the 20 most popular authors.

Your job is to find the most and least popular genres among these authors, along with their average sales revenue.

This exercise is part of the course

Introduction to Python for Developers

View Course

Exercise instructions

  • Check if average_sale is equal to the largest sales revenue (5166000000) in genre_sales.
  • Print the genre with the largest average sales.
  • Next, check whether average_sale is equal to the smallest sales revenue (80000000).
  • Lastly, print the genre with the smallest average sales.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

for genre, average_sale in genre_sales.items():
    
    # Filter for the maximum sales value
    if _____ 5166000000:
      
      # Print the genre
      print("Most popular genre: ", _____)
      print("Average sales: ", average_sale)
    
    # Filter for the minimum sales value
    elif _____ 80000000:
      
      # Print the genre
      print("Least popular genre: ", _____)
      print("Average sales: ", average_sale)
Edit and Run Code