Code in Place

Welcome to Section!

Week One

Agenda

  • Intro / Getting to Know you ~15min
  • Concept review ~5min
  • Section Puzzle ~20min

About Section

  • A Community of learners
  • Collaboration
  • Coding as a way of thinking
  • Not a lecture -- a place to do
  • You get what you put into it

Section Norms

  • Respect for one another
  • Patience -- we're all learners!
  • Have fun!

Introductions

About Me:

  • Jeff DazĂ©
  • Senior Software Engineer
  • Musician
  • Toronto ON, Canada
  • My first time leading a section!

About You!

  • Name
  • Where in the world?
  • In chat: an emoji that represents how you're feeling today
  • One thing you're looking forward to!

How to get the most out of Section?

  • This is YOUR time
  • Finishing the puzzle isn't the important part...
  • Exploring the puzzle and HOW we can solve it is!
  • Again, programming is a way of thinking!

Lecture Review

What We've learned

  • Basics of Karel
  • Functions
  • Control Flow (loops and conditionals)

Karel Overview

Karel is like a robot / remote control car with a small set of commands! (this is on purpose):

  • move()
  • turn_left()
  • pick_beeper()
  • put_beeper()

Functions

Functions are a way to define a set of steps into a logical unit.


						def function_name():
							# Some function code goes here
					
						# Turning left three times goes right!
						def turn_right():
							turn_left()
							turn_left()
							turn_left()
					

Control Flow

  • For Loop
  • While Loop
  • If Statement

For Loop

A for loop runs for a set number of times


					def turn_right():
						for i in range(3):
							turn_left()
					

While Loop

A while loop runs until a condition is no longer true -- CAUTION! that could mean forever!


						def move_to_wall():
							while front_is_clear():
								move()
					

if statement

An if statement executes if the condition is true


						def safe_move():
							if front_is_clear():
								move()
					

Review Questions?

Section Puzzle: Hospital Karel

Puzzle Handout

IDE Link

Countries around the world are dispatching hospital-building robots to make sure anyone who gets sick can be treated. They have decided to enlist Karel robots, and your job is to program those robots.

Beepers are piles of supplies that tell us where to build each hospital

Karel should move along this row to find each pile of supplies

The hospital buildings are built of a 3 by 2 rectangle of beepers:

When Karel encounters a pile of supplies, that's where the building starts:


Starting with this world we should end up with this final result:


Puzzle Questions?