Karel - Code HS
Karel = dog who listens to commands
can be programmed to move around the world + put down tennis balls
Programming/coding = giving commands to computer
Karel knows 4 commands:
move() #moves Karel one space forward
turn_left() #moves Karel 90 degrees to left
put_ball() #puts down 1 tennis ball where Karel is standing
take_ball() #picks up 1 tennis ball where Karel is standinghas to be 1 of 4 statements
no spaces in commands
multiple words separated w/ underscore
each statement has to be lowercase/match exact capitalization
every command ends in ()
doing the following 4 times in a row makes karel turn all the way around (“dancing”)
turn_left()rows are called streets + they start at 1
columns are called avenues + also start at 1

comments in python start w/ #
turn_left() makes direction go counterclockwise
NOTE: FIGURE OUT KAREL DIRECTIONS
Question*
Question: 4
If Karel is facing North and the code
turn_left() turn_left()runs, which direction is Karel facing now?
North
South
East
West
To make Karel turn right, use the following:
turn_left()
turn_left()
turn_left()
#acts as a turn_right()Function = way to teach Karel a new word
allows us to break program into smaller parts, makes program easier to understand + avoids repeating code over and over
simplifies problem solving process + helps others understand code
to write function, do the following:
def function_name():
#commands that karel known
#always tab
#when indenting is stopped, next thing isn't a function
#define function before called
move()def in a function means define
rules for naming functions:
names should start w/ a letter + can’t have any spaces
all letters should be lowercase + words should be separated w/ underscore (referred to as snake_case)
name of func should describe what function is doing
name should start w/ action verb + sound like command
defining a func: teaching Karel new word; writing instructions
calling a func: actually getting Karel to do command; causing the action to happen
top down design: breaker bigger problem into smaller and smaller problems until there is a simple problem
decomposition = breaking program down into small + manageable parts that are easy to understand
helps us solve large complicated problems + helps make code more readable + allows to collaborate
preconditions: what assumptions we make + what must be true before the function is called
ex. Karel has jumped the last hurdle + is facing east
postconditions: what should be ture after the function is called
ex. Karel has reached the finish line
abstraction = managing complexity by “abstracting away” info + detail, in order to focus on relevant concepts
procedural abstraction = defining steps of a program w/o worrying abt exactly how each step works under the hood
programming languages abstract away all complex details
modularity = subdivision of a computer program into separate subprograms (for computers)
API = application programming interface; set of tools for building programs/software
Karel is an API built in Python to make it easier to build cool programs quickly
abstracts away complex details involved in getting Karel to move across screen
documentation = imp part of API b/c it shows programmers info abt how to use it
SuperKarel knows the following commands:
move()
put_ball()
take_ball()
turn_left()
turn_right()
turn_around()