Homework 11 -- Python (Functions, Mutation, Equality)
Skills Practiced:
Introduction
You're building a music streaming service called "TuneTracker". The system needs to manage playlists, track listening statistics, and analyze user preferences. Throughout this assignment, you'll explore how Python handles functions, variable mutation, and different types of equality in the context of music data.
Problem 1
Design a function calculate_song_popularity
that takes three parameters:
- play_count (int): Number of times the song has been played
- likes (int): Number of likes the song has received
- shares (int): Number of times the song has been shared
The function should return a popularity score using this formula:
- Play count contributes 60% of the score (normalized by dividing by 1000)
- Likes contribute 30% of the score (normalized by dividing by 100)
- Shares contribute 10% of the score (normalized by dividing by 10)
Problem 2
Design the function total_listening_time
that takes a list of song durations (in seconds) and returns the total time.
Problem 3
Part A
Design a function extend_songs_immutable
that adds 10 seconds to every song duration in a playlist, returning a new list without modifying the input.
Part B
Design a function extend_songs_mutable
that adds 10 seconds to every song duration in a playlist, modifying the input list directly using list indexing.