Code in Place Week 1

I taught my first section for Code in Place on Thursday! They have done a fantastic job at providing so much teaching material. So the way it’s structured is that on Sundays, the lessons and coding problems are posted. Students watch and do these asynchronously. Then students attend Section, which happens sometime between Wednesday - Saturday. In section students solve a problem.

To prepare for week 1, Code in Place gave me Learning Objectives, Explained what I can assume students already know and a suggested session plan! 

So me being extra (and honestly to keep in on track) I made slides. Check it out at: bit.ly/cip-week1. It goes over the logistics, section policies, ice breaker with the section, review the week’s key concepts and then we jumped into coding!

This week’s key concepts were:

  • Approaching a problem

  • Control Flow

  • Decomposition

Approaching a problem

I shared 3 steps on approaching a problem (which totally brought me back to my old Whiteboarding class, where I recommended similar steps). So I’m starting these students off with good habits!

Control Flow

We reviewed if, else, and loops:

  • statements: line of code that is not if, else, for or while

      move()
  • if: Do something when a condition is met

      if front_is_clear():
            move()
  • else: Do something when a condition is met, if condition not met, then do the else code block

      if front_is_clear():
            move()
      else:
            turn_left()
  • for loops: Do something a set number of times.

      for i in range(3):
            move()
  • while loops: Do something until condition is no longer true

      while front_is_clear():
            move()

Then we walked through different questions they can ask themselves as they are trying to figure out which item to use:

Decomposition

Decomposition is the process of breaking a program down into smaller pieces. They can do that by creating new functions that solve the smaller pieces and in our main function they can call the new functions. Another word for these new functions are called helper functions.

I gave them examples of some code and asked them which one was easier to read and understand. I also asked them what they thought is the pros/cons of breaking their code down into specific pieces.

Coding

Then we jumped into solving a problem using Karel. Karel is a web based program of a little robot, Karel, and Karel’s simple world. Karel already knows some simple commands like turning left, but not others like turning right. It’s super cute and a great tool to learn to code. 

We spent about 20 mins working on solving a problem as a group. I was really impressed by how far we got especially considering the time limit, doing it as a group and it was our first time trying to solve a problem as a group. It wasn’t as pithy as I would have wanted it, but overall the students did great with making suggestions, asking questions and noticing potential issues.

The problem we were working on was that Karel is walking along (always from left to right) and if Karel finds a bag of supplies (in the program it's called a beeper), that Karel should build a hospital. 

Check out a visualizer of what the code below does: https://codeinplace.stanford.edu/cip3/share/AK6CF7g4tAmdZbm6tlOJ

from karel.stanfordkarel import *

# Here is a place to program your Section problem

def main():
    """
    You should write your code to make Karel do its task in
    this function. Make sure to delete the 'pass' line before
    starting to write your own code. You should also delete this
    comment and replace it with a better, more descriptive one.
    """
    # while loop -> front_is_clear()
        # check if there is a beeper
            # build hospital
        # move
    # while front_is_clear():
    #     if beepers_present(): 
    #         build_hospital() # TODO
    #     move() # tobias shared concerns about possible error here
    while front_is_clear():
        move()
        if beepers_present():
            build_hospital()

    
        
def build_hospital():
    """Builds a 2 column hospital using beepers and set's Karel up to continue walking"""
    
    build_first_column()
    build_second_column()
    turn_left()


def build_first_column():
    """Builds the first column of the hospital, leaving Karel on top of the column"""
    turn_left()
    for i in range(2):
        move()
        put_beeper()
    

def build_second_column():
    """Gets Karl from the first column into the position fo the second column and then builds the second column of the hospital, leaving Karel facedown"""
    turn_right()
    move()
    turn_right()
    put_beeper()
    
    for i in range(2):
        move()
        put_beeper()


def turn_right():
    """3 lefts = right"""
    for i in range(3):
        turn_left()


if __name__ == '__main__':
    main()

Other

On Wednesday my section had 16 students and by Thursday had 12 students. I hope that the 12 keep going and complete the course🤞🏽

Previous
Previous

Week 2 of Code in Place

Next
Next

Using Chat GPT to write my last 5 years of work experience