🐍
[PY] Intro to Computational Media 2.0
CS4All Resources
  • Curriculum Overview
  • How to Use this Curriculum
  • 📬Leave Us Feedback
  • Curriculum Extras
    • 🔮Curriculum Extras Overview
    • Imposter Syndrome (pt. 1)
      • Imposter Syndrome (pt. 2)
    • Timers in Processing.py
    • Time Functions: Crazy Clock Mini Project
    • Pathfinding Algorithms and Facial Scanning
    • Playing with Pixels
  • Unit 1: Draw & Draw With Functions
    • 🔮Unit 1 Overview
    • U1LA1.1: Processing.py Introduction & Deconstruction
    • U1LA1.2 Line Functions and Parameters
    • U1LA1.3: Rectangles, Ellipses, and Layering
    • U1LA1.4: Other Shapes & Styling
    • 🗃️U1LA1 Mini Project: Taijitu Symbol
    • U1LA2.1: Intro to Color with RGB and HSB
    • 🤓EXTRA: Color & Data Storage
    • 🤓EXTRA: Color Palette Practice
    • ✨U1LA3.1: Introducing Variables
    • ✨U1LA3.2: Creating Custom Variables
    • ✨U1LA4.1: What is Abstraction?
    • ✨U1LA4.2: Intro to Functions and Function Calls
    • U1LA4.3: Draw with Functions
    • U1LA4.4: Using the Random Function
    • 🗃️U1LA4 Mini Project: Custom Emoji
    • U1LA5.1: Your Custom Function Library
    • 🎨Unit 1 Final Project: Abstract Album Art
  • Unit 2: Respond and Draw On Canvas
    • 🔮Unit 2 Overview
    • ✨U2LA1.1: Conditionals and If Statements
    • ✨U2LA1.2: Conditionals and if, elif, and else statements
    • ✨U2LA1.3: Logical Operators And/Or
    • 🗃️U2LA1 Mini Project: Make a Traffic Light
    • U2LA2.1: Draw with Mouse
    • U2LA2.2: The Map Function
    • ✨U2LA3.1: Data Type Scavenger Hunt
    • ✨U2LA3.2: Functions that Return Values
    • 🤓U2LA3.3: Functions with Purpose
    • U2LA4.1: Collision Functions and Libraries
    • U2LA4.2: Mouse Clicks and Shapes as Buttons
    • 🗃️U2LA2 Mini Project: Light Switch Game
    • U2LA5.1: Key Presses and Nested Conditionals
    • 🎨Unit 2 Final Project: Interactive Drawing App
  • Unit 3: Loops, Arrays, Media
    • 🔮Unit 3 Overview
    • U3LA1.1: While Loops
    • U3LA1.2: For Loops Pt. 1
    • U3LA1.3: Nested For Loops (For Loops Pt 2)
    • 🗃️U3LA1 Mini Project: Wallpaper Design
    • U3LA2.1: Introduction to Lists
    • U3LA2.2: Random Values from Lists
    • 🗃️U3LA2 Mini Project 1: Fortune Teller
    • U3LA2.3: Loops and Lists
    • U3LA2.4: Updating and Deleting from Lists
    • 🗃️🤓 U3LA2 Mini Project 2: CodeWars List Challenges
    • U3LA3.1: Loading Images
    • 🗃️U3LA3 Mini Project: Vision Board
    • 🎨Unit 3 Final Project: Random Meme Generator
  • Unit 4: Motion, Objects, Transformation
    • 🔮Unit 4 Overview
    • U4LA1.1: Intro to Motion with Flipbooks
    • U4LA1.2: Move in All Directions and Make it Bounce
    • U4LA2.1: Introduction to Classes and Objects
    • U4LA2.2: Reading and Updating Object Properties
    • U4LA2.3: Methods Off Canvas
    • U4LA2.4: Objects on Canvas
    • 🗃️U4LA2 Mini Project: Build a Tamagotchi
    • U4LA3.1: Creating Many Objects
    • 🤓🗃 Optional U4LA3 Mini Project: Rebuild with Objects
    • U4LA4.1: Translation Battleship
    • U4LA4.2: Rotations
    • 🤓U4LA5.1: Sine and Oscillating Motion
    • 🤓U4LA5.2: Cosine and Circular Motion
    • 🎨Unit 4 Final Project: Animated Greeting Card or PSA
  • Unit 5: Final Project
    • 🔮Unit 5 Overview
    • 🎨Course Final Project Guide
Powered by GitBook
On this page
  • Teacher Notes
  • Resources
  • Launch & Prompt
  • Sample Outputs
  • Extensions
  1. Unit 3: Loops, Arrays, Media

🤓 U3LA2 Mini Project 2: CodeWars List Challenges

How can I use lists and loops to solve code challenges?

PreviousU3LA2.4: Updating and Deleting from ListsNextU3LA3.1: Loading Images

Last updated 2 years ago

Teacher Notes

This is an optional mini-project. Similar to U2LA3.3, it asks students to work on CodeWars where they will practice their coding skills on a series of challenges that focus on utilizing lists, loops, and related methods.

This lesson could, if necessary, be considered optional, as it does not build onto the p5.js library, but rather focuses on fundamental JavaScript skills in building functions with lists and loops. Time permitting, we strongly recommend you give it a go with students to stretch their logic muscles and give them a shot at something new!

We recommend doing a quick launch together to ensure students recall how to use CodeWars. Then, students can work with a programming partner or in small groups to complete the remaining challenges. (You may, as always, have students work independently, but that's never near as fun!)

NB: As CodeWars utilizes many different programming languages, you may see them use the word 'array' in place of 'list'. While technically students are just using lists in Python - arrays have slightly different properties in this language - we should consider them interchangeable for the purpose of these exercises.

Resources

Launch & Prompt

To begin, review the Whole Class Example together. In this example, students are asked to sum a list and then return if the sum is odd or even. The summing is easy enough - it would look something like this:

def odd_or_even(arr):
    sum = 0
    
    for num in arr:
        sum += num

While this helps us with the sum, we still do not know if our sum is odd or even. We can solve that with a neat little operator called a modulo! This may or may not be brand new to students.

An easy way to quickly teach them modulos is to tell them that a modulo - written as % in our code, or sometimes MOD in pseudocode - does a very special type of division. Ask them to look at these examples and figure out any patterns/noticings:

  • 11 % 2 = 1

  • 10 % 2 = 0

  • 13 % 2 = 1

  • 14 % 4 = 2

  • 16 % 4 = 0

  • 15 % 4 = 3

  • 24 % 6 = 0

  • 25 % 5 = 0

  • 25 % 3 = 1

  • 26 % 13 = 0

  • 26 % 8 = 2

What they should have noticed is that a modulo is always returning the remainder of a division problem.

We can use this and what we know about even and odd numbers to help us finish our challenge. Even values are always evenly divisible by 2, while odd values will always have a remainder of 1 when divided by 2. So we could adjust our code to the following:

def odd_or_even(arr):
    sum = 0
    
    for num in arr:
        sum += num
    
    if sum % 2 == 0:
        return "even"
    else:
        return "odd"

Remind students to use the test button in CodeWars to check themselves, then copy/paste their code over to their Google Doc before they hit submit and run the final round of tests.

Students will work in pairs or small groups to solve the remaining challenges. It is up to them to determine what level they would like to begin at - a good rule of thumb is that if they are feeling stumped, to go down a level or pop open a new tab and do a little googling.

As the teacher, you can determine parameters for grading/requirements for completion - perhaps they need to do all 3 mild and 2 medium, or 1 medium, 2 mild, 1 spicy, or some other iteration that you think would show proper mastery.

Sample Outputs

The best part about CodeWars is that when you complete a challenge, you can view the possible answers from people around the world! These may look more elegant than student solutions - many people who use CodeWars are college students or professionals looking to practice - but they can still be valuable for insight.

It is strongly recommended that you work through as many of the challenges as possible yourself prior to assigning this to students so that you can help them through any sticking points.

Extensions

While there are no planned extensions, advanced students or groups should focus on the spicy-level problems first. If they complete these quickly, there is a whole world of problems on CodeWars that they should be able to keep busy with!

🗃️
U3LA2: Mini Project 2 Google Doc