Practice Fork

From the tutorial

  • lists
  • loops
  • functions

Read-only

Rotate a playlist

A radio station keeps a playlist as a list of track names. Write rotate_playlist(tracks, n) so the last n tracks move to the front and the function returns a new list. If n is 0, return a copy of tracks. If the playlist is empty, return an empty list. If n is larger than the playlist, wrap around the length. Do not call a music API, and do not reuse the tutorial's task rotator. Example: rotate_playlist(["a", "b", "c", "d"], 1) returns ["d", "a", "b", "c"].

Rubric

  • nameDefines rotate_playlist
  • listUses a list
  • wrapWraps around the length
  • emptyHandles an empty playlist
  • zeroHandles a zero rotation

TRANSFER

100

Transferred

You applied lists and loops to the playlist brief, including the wrap.

Three gaps to close

  1. Concept: transferChange one noun in “Rotate a playlist” and rewrite the solution in your own names.
  2. Concept: listsAdd one edge the brief did not spell out, and say in a comment why you handled it.
  3. Concept: readingRead the answer aloud without using the tutorial’s example names.
Fork a lab