The following is an activity that we developed for a week-long summer coding camp called Data for Social Good. The activity aimed to be accessible to a wide range of age groups (6th through 9th grade) and to motivate interest in the syntax of repetition through the development of interactive entertainment.
Curricula Outline: Introduction to For-EaCh LoopS
Materials:
- Computers
- Projector
- Jupyter Access / Accounts
- Jupyter Worksheet: Kinda Karaoke For-Each-Loops Worksheet
- (For Possible Extension Only) Headphones & Headphone Splitters
What Instructors Should Know:
- Teaching Strategies:
- Encouraging students to read and interpret instructions and error messages
- Referring to previously written code (particularly previously written code in the document)
- Content:
- Range, For-Each syntax, list-indexing
Main Topic:
- An introduction to For-Each loop syntax
- An introduction to Markdown
Objectives:
- Introduce students to the uses of For-Each loops in Python
- Repetition, accessing elements of one list, accessing elements of multiple lists, nested loops
- Have students play with a new library: time
Introduction to Main Topic:
- Demo: Have students guide instructor through the following activities in a blank Jupyter document (15 min)
- Introduce students to Markdown throughout the demo
- Type up thoughts on projector… headings, bold text, code examples…
- Let’s make a list (of anything really). How do we make a list?
- How would we print the list?
- How do we print the first element in the list?
- How do we print all of the elements in the list on separate lines?
- Using indices here could be a little tedious (and a lot of lines of code). We don’t want to do this work (especially if our list is long).
- So how do we write less code…
- Possibly ask students to remember previous activity from a presentation on loops. (Specifically the use of repetition to walk in a square around a chair)
- Let students know that they really only “need” counselors for syntax (especially in this case).
- Show students how to write a for-each loop to print elements on separate lines.
- Introduce students to Markdown throughout the demo
List of Short Activities:
- Leave code from demo on the projector
- Students work on Worksheet (link above) (30-55 minutes)
- If students have difficulties understanding the combination of range and list indexing do a demo on the whiteboard.
Debrief (Optional):
- Students share songs by having other groups attempt to sing them.
Possible Extensions:
- Direct Students to EarSketch, a platform that teaches coding fundamentals using the development of music in Python.
Reflection
The activity went according to plan. The short demo ensured that students felt that they had some guidance but were not bored into complacency. Leaving code up on the screen provided students with a general format for a For-Each loop. All groups completed up through Part 3, which covered the bulk of the material that would be applied to future Data Science projects. Students that encountered problems concerning range and indexing were able to apply preexisting code to solve their problems with a little bit of help. The activity contained enough content that only one group made it to the extension, yet broke problems up into pieces such that slower groups still felt a sense of accomplishment. In the future, allocating more time to the activity would ensure that every group created a completed product. This could increase students’ sense of self-efficacy more than the current activity.