0% found this document useful (0 votes)
11 views

Code in Place_Lesson 1_slides

Code in Place is a community service project aimed at teaching programming through Python, led by professors Mehran Sahami and Chris Piech. The course is designed for learners from diverse backgrounds and is offered for free, focusing on problem-solving skills and the joy of learning. Participants will engage with Karel the Robot to learn programming concepts in a hands-on manner.

Uploaded by

laurelcore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Code in Place_Lesson 1_slides

Code in Place is a community service project aimed at teaching programming through Python, led by professors Mehran Sahami and Chris Piech. The course is designed for learners from diverse backgrounds and is offered for free, focusing on problem-solving skills and the joy of learning. Participants will engage with Karel the Robot to learn programming concepts in a hands-on manner.

Uploaded by

laurelcore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Lesson 1

Welcome to Code in Place

Piech and Sahami, Code in Place


In this first video

Meet the Team

What is Code in Place?

After: Learn to Code!


Piech and Sahami, Code in Place
Meet the team!

Piech and Sahami, Code in Place


Mehran Sahami

• Childhood: Iran
• High School: San Diego
• Stanford University Ph.D. in Machine Learning
(Before Machine Learning was cool)
• Spent a decade in tech industry before coming back as professor
• Love of teaching is why I came back

Piech and Sahami, Code in Place


Mehran Sahami

Piech and Sahami, Code in Place


Chris Piech
Invented the
algorithm
behind bird
brain

Lead a research lab in:


Future of Education

Grew up in Nairobi, Kuala Lumpur before Stanford!

Piech and Sahami, Code in Place


What An Awesome Team

Piech and Sahami, Code in Place


It Takes a Village!

Piech and Sahami, Code in Place


What is Code in Place?

Piech and Sahami, Code in Place


Code in Place:

1/2 of CS106A
As Community Service

Piech and Sahami, Code in Place


Learners from over 150 countries
and all walks of life have completed this course

Piech and Sahami, Code in Place


This class is just for fun
(what could be more fun than learning)

Piech and Sahami, Code in Place


We are doing this as volunteer
work. You get a class for free!

Piech and Sahami, Code in Place


Learning Goal

Learn how to solve


problems with
python

Find the joy


of a new skill

Piech and Sahami, Code in Place


Course Plan

Karel
Karel

Data
Graphics

Piech and Sahami, Code in Place


Programming Along the Way

Piech and Sahami, Code in Place


Course Values

Piech and Sahami, Code in Place


Art of Computer Science

Piech and Sahami, Code in Place


Learn by Doing

Footer Text 19
4/9/20 Piech and Sahami, Code in Place
Gratitude

Piech and Sahami, Code in Place


Everyone is Welcome

Piech and Sahami, Code in Place


We are all learners, teachers

This is a collective
community service
project. You are part of
our community.

Help us make this work.

Piech and Sahami, Code in Place


Let’s learn!

Piech and Sahami, Code in Place


Meet Karel the Robot
Rich Pattis

Good morning

Piech and Sahami, Code in Place


Karel Speaks Python

Piech and Sahami, Code in Place


Why Python?

1 Program language popularity

yth on
p

2012
2019

https://stackoverflow.blog/2017/09/06/incredible-growth-python/
Piech and Sahami, Code in Place
Guido van Rossum

Piech and Sahami, Code in Place


Karel’s World
North

“columns” run
Left/Right West East

South
3 + + + + +

Bottom/Top
“rows” run
2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


Walls

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


Beepers

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


Knows Four Commands

move()
turn_left()
put_beeper()

pick_beeper()

Piech and Sahami, Code in Place


move()

Piech and Sahami, Code in Place


move()

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


move()

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


turn_left()

Piech and Sahami, Code in Place


turn_left()

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


turn_left()

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


pick_beeper()

Piech and Sahami, Code in Place


turn_left()

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


turn_left()

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


Make Sense?

Piech and Sahami, Code in Place


Bird’s Eye View

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


Bird’s Eye View

Karel is facing East

Piech and Sahami, Code in Place


Turn Left

Karel is facing North

Piech and Sahami, Code in Place


Turn Left

Karel is facing West

Piech and Sahami, Code in Place


Turn Left

Karel is facing South

Piech and Sahami, Code in Place


Move

Piech and Sahami, Code in Place


First Challenge

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


First Challenge

3 + + + + +

2 + + + + +

1 + + + + +

1 2 3 4 5

Piech and Sahami, Code in Place


Midjourney
Piech and Sahami, CodeAI
in Place
Learn By Doing

Piech and Sahami, Code in Place


Piech and Sahami, Code in Place
Function Definition

def name():
function statements

a n ew
d d s r e l 's
a a
This nd to K
m a l a ry
com a b u
v oc

Piech and Sahami, Code in Place


Anatomy of a Program
Import Packages

Program

Piech and Sahami, Code in Place


Anatomy of a Program
Import Packages

Piech and Sahami, Code in Place


Anatomy of a Program
Import Packages

def main():
move()
pick_beeper()
move()
turn_left()
main function
move()
turn_right()
move()
put_beeper()
move()

def turn_right():
turn_left()
helper functions
turn_left()
turn_left()
if __name__
start == "__main__":
program
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
Import Packages

def main():
move()
pick_beeper()
move()
turn_left()
move()
turn_right()
move()
put_beeper()
move()

def turn_right():
turn_left()
helper functions
turn_left()
turn_left()
if __name__
start == "__main__":
program
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
Import Packages

def main():
move()
pick_beeper()
move()
turn_left()
move()
turn_right()
move()
put_beeper()
move()

def turn_right():
turn_left()
turn_left()
turn_left()
if __name__
start == "__main__":
program
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
Import Packages

def main():
move()
pick_beeper()
move()
turn_left()
move()
turn_right()
move()
put_beeper()
move()

def turn_right():
turn_left()
turn_left()
turn_left()
if __name__ == "__main__":
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
from karel.stanfordkarel import *

def main():
move()
pick_beeper()
move()
turn_left()
move()
turn_right()
move()
put_beeper()
move()

def turn_right():
turn_left()
turn_left()
turn_left()
if __name__ == "__main__":
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
from karel.stanfordkarel import *

def main():
move()
pick_beeper()
move()
turn_left()
move()
turn_right()
move()
put_beeper()
move()

def turn_right():
turn_left()
turn_left()
turn_left()
if __name__ == "__main__":
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
from karel.stanfordkarel import *

def main():
move()
pick_beeper()
move()
turn_left() This piece of the
move() program's source code is
turn_right() called a function.
move()
put_beeper()
move()

def turn_right():
turn_left()
turn_left()
turn_left()
if __name__ == "__main__":
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
from karel.stanfordkarel import *

def main():
move()
pick_beeper()
move()
turn_left()
move() This line of code gives the
turn_right() name of the function
move() (here, the name is: main)
put_beeper()
move()

def turn_right():
turn_left()
turn_left()
turn_left()
if __name__ == "__main__":
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
from karel.stanfordkarel import *

def main():
move()
pick_beeper()
move()
turn_left()
move() This line of code gives the name of
turn_right() the function
move() (here, the name is: turn_right)
put_beeper()
move()

def turn_right():
turn_left()
turn_left()
turn_left()
if __name__ == "__main__":
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
from karel.stanfordkarel import *

def main():
move()
pick_beeper()
move()
turn_left() This is called a code
move() block
turn_right() (Note the indenting)
move()
put_beeper()
move()

def turn_right():
turn_left()
turn_left()
turn_left()
if __name__ == "__main__":
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
from karel.stanfordkarel import *

def main():
move()
pick_beeper()
move()
turn_left() This is called a code
move() block
turn_right() (Note the indenting)
move()
put_beeper()
move()

def turn_right():
turn_left()
turn_left()
turn_left()
if __name__ == "__main__":
run_karel_program()
Piech and Sahami, Code in Place
Anatomy of a Program
from karel.stanfordkarel import *

def main():
move()
pick_beeper()
move()
turn_left() This is called a code
move() block
turn_right() (Note the indenting)
move()
put_beeper()
move()

def turn_right():
turn_left()
turn_left()
turn_left()
if __name__ == "__main__":
run_karel_program()
Piech and Sahami, Code in Place

You might also like