Seksjon 3. Kapittel 3
solution.py
main.py
Tracks Total Duration
Sveip for å vise menyen
Oppgave
Swipe to start coding
Complete a function that calculates the total duration of all tracks in a list, converting the duration from milliseconds to minutes. Each track is represented as a dictionary containing various fields, including a duration_ms field that indicates the track's duration in milliseconds.
Inputs:
tracks: A list of dictionaries, where each dictionary represents a track and contains at least the following field:duration_ms: An integer representing the duration of the track in milliseconds.
Steps:
-
Iterate Through Tracks:
- Loop through each track in the
trackslist. - For each track, add its
duration_msvalue tototal_duration_ms.
- Loop through each track in the
-
Convert to Minutes: After summing the durations in milliseconds, convert
total_duration_msto minutes by dividing it by 60,000 (since there are 60,000 milliseconds in a minute).
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 3
solution.py
main.py
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår