VR - Mission 14: Music Box
Music Box
Students turn CodeBot into a jukebox, using a dictionary of notes and Python's file operations to open, read, write, and play songs stored in text files.
Overview
In this mission, students turn CodeBot into a jukebox. They build a dictionary of notes and pitches, then use a list of notes to play a song, and expand that to a matrix of notes and beats. Along the way they learn Python's file operations: opening, reading, writing, and closing text files, and converting string data pulled from a file into a matrix (a list of lists) the 'bot can play. The mission wraps up with a jukebox program that cycles through songs when a button is pressed.
π― Mission Goal: Students will turn the CodeBot into a jukebox and learn about Python's file operations.
Learning Targets
- I can use a dictionary of notes to play different pitches.
- I can use a list of notes to play a song by accessing the dictionary of notes.
- I can open, read, write to, and close a text file.
- I can play a tune using a matrix of notes and beats.
- I can convert string data from a file into a matrix.
Key Concepts
- A dictionary of notes is useful for storing data that is used frequently.
- The Python file system allows you to open, read, and write to a file in many ways.
- You should always close or flush a file after it is opened.
- String data can be converted to an integer.
- String data from a file can be converted to a list of lists using file operations.
Assessment Opportunities
- Submit program code, or give students printed code and have them explain each line: Objective 3, Objective 6, Objective 8
- Give extra practice with file operations
- Give extra practice with iterating over a list
- Code Tracing Chart as a debugging tool
- Submit final jukebox program
- Mission 14 Review Kahoot!
Success Criteria
- Create a dictionary of notes and pitches.
- Iterate over a list of notes and beats to play a song.
- Open, read, and close a file.
- Convert string data from a file into a matrix (list of lists).
- Program CodeBot to cycle through songs like a jukebox when a button is pressed.
Digital Resources
Classroom Materials
- βΈComputer or Chromebook with internet access
Real-World Applications
Extensions & Cross-Curricular
π€
Vocabulary
βΎ
π
New Python Code
βΎ
π
Standards
βΎ
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
Certiport IT Specialist: Python Standards
PCEP: Certified Entry-Level Python Programmer
- Remember to zoom in enough inside the 3D environment to hear the speaker.
- Preview the objective walkthrough videos (Obj 2, 5, and 7) so you can point students to the right one when they get stuck.
- Have the Code Tracing Chart ready to use as a debugging tool for Objectives 3, 6, and 8.
- Plan checkpoints for the code submissions at Objective 3, Objective 6, and Objective 8, plus the final jukebox program.
- Remember to zoom in enough inside the 3D environment to hear the speaker.
- When typing a long list, it can be divided up into more than one line, just like a dictionary, for easy reading.
- Make sure students include the file extension in the name for the open command.
- Programming concepts used are: dictionaries, iterating over a list, using a matrix, and file operations. Review them as needed.
Lesson Outline
Ask students how a jukebox or music app "knows" which song to play and how it stores the notes of a song. Introduce the idea that CodeBot can store songs the same way, as data in a dictionary, a list, and eventually a file, and that today's mission builds toward a working jukebox program.
- Build a dictionary of notes and pitches using Scientific Pitch Notation, then iterate over a list of notes to play a song by looking up each pitch in the dictionary.
- Reference Mission 14 Obj 2 as needed.
- Submit program code, or give students printed code, and have them explain each line for Objective 3.
- Open, read, and close a text file. Practice the different file modes (read-only, write, and read and write), and always remember to close or flush a file after opening it.
- Reference Mission 14 Obj 5 as needed.
- Give extra practice with file operations, then submit program code or have students explain printed code for Objective 6.
- Build a matrix (a list of lists) of notes and beats, then unpack it with a for loop to play a tune with both pitch and rhythm.
- Reference Mission 14 Obj 7 as needed.
- Give extra practice iterating over a list, then submit program code or have students explain printed code for Objective 8. Use the Code Tracing Chart as a debugging tool if students get stuck.
- Convert string data pulled from a file into a matrix of notes and beats, then program CodeBot to cycle through songs like a jukebox when a button is pressed.
- Have students submit their final jukebox program.
Close with the Level-1 Mission 14 Review Kahoot! to reinforce dictionaries, lists, matrices, and file operations before moving on to the Unit 6 Remix & Assessment.