Homework 6 -- Lists (Iteration)
Skills Practiced: 3
Idea: extracting columns from a table, doing custom calculations over them.
Introduction
You're working as a data analyst for an online bookstore. The company has provided you with a sales table containing information about book orders. Your job is to extract columns from this table and perform various calculations to help the business understand their sales patterns.
Assume you have access to a table called book-sales
with the following columns:
book-sales = table: title, genre, price, quantity-sold, customer-rating, shipping-cost
row: "1984", "Fiction", 14.99, 127, 4.3, 3.99
row: "Crime and Punishment", "Fiction", 16.99, 203, 4.7, 3.99
row: "Where the Crawdads Sing", "Fiction", 15.99, 312, 4.1, 3.99
row: "Atomic Habits", "Self-Help", 18.99, 189, 4.6, 3.99
row: "Klara and the Sun", "Sci-Fi", 26.99, 95, 3.9, 5.99
row: "Project Hail Mary", "Sci-Fi", 28.99, 167, 4.8, 5.99
row: "Evicted", "Non-Fiction", 16.99, 203, 4.7, 3.99
end
Problem 1
Design a function sort-ratings
that categorizes books as "Highly Rated" (≥ 4.5), "Well Rated" (4.0-4.4), or "Needs Improvement" (< 4.0).
Problem 2
Design a function satisfaction-score
that calculates which books contribute most to overall customer happiness using the formula rating x quantity-sold.
Problem 3
Design a function average-price-per-genre
that calculates the average price for books in each genre.
Problem 4
Design a function performance-index
that creates an "overall performance index" using the formula: (quantity-sold ÷ 10) + (customer-rating x 5) + (price ÷ 2)
.