← 2023 questions

2023 / SPOTIFY / QUESTION 8

Shuffle play

Try the question in your own editor, then check your output below.

THE QUESTION

Vignesh likes to use the shuffle play function on Spotify so that he gets a diverse and unique listening experience. Shuffling happens at random.

Output a random track number e,g. "Daydreaming by Harry Styles" is 0 AND its track name. Use a count loop to output this three times.

(Hint: explore the import random function)

Use the following code as a starting point:

import random
track = [["Daydreaming by Harry Styles"],
[ "Workin Out by JID"],
["Old Love by yuji"],
["Eventually by Tame Impala"],
["After Hours by The Weekend"],
["Ghostin by Ariana Grande"],
["Hey, Mickey! by Baby Tate"],
["Low by SZA"],
["Pink + White by Frank Ocean"],
["Here With Me by d4vd"]]

Example of output (everyone's output will be different since it is randomised):

9
['Here With Me by d4vd']
5
['Ghostin by Ariana Grande']
7
['Low by SZA']

Question by Elena. Source: Girls In Code SEA — Behind the Screens, 2023, slide 23.

PRACTICE CHECK

Try your answer.

This checks track/index consistency, not randomness.

Run your program in your own editor, then paste its output below. This checks the stated output or checkpoint; it does not assess your full program. Practice attempts do not affect competition scores.

Enter three lines, each containing the zero-based track number followed by its name. Repeats are allowed.

Reveal worked answer

Three shuffled tracks · one valid answer

9 Here With Me by d4vd
5 Ghostin by Ariana Grande
7 Low by SZA

Choose an index in range(10) three times and output the matching track. Every valid combination is accepted.