1/21
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
regular karel knows…
4 commands:
move()
turn_left()
put_ball()
take_ball()
rows:
columns:
streets
avenues
a function
a way to teach karel a new word
def name of function ():
indent + command
why do we use functions?
break program into smaller parts
make the program easier to understand
naming your function
start with a letter, no spaces
snake_case
lowercase and use underscore
start with an action word and should sound like a command
top down design
breaking a big problem down into smaller parts
helps to solve complicated problems
allows to collaborate and split tasks
comments
break down your problem
make your code clear to others
multi-line: ‘‘‘comment’’’
single line: #comment
preconditions: assumptions we make, and what must be true
postconditions: what should be true after the function is called
abstraction
managing complexity by “abstracting away” info and details
to focus on more relevant details
SuperKarel
two new functions:
turn_right()
turn_around()
API
application programming interface
is a set of tools for building programs
For loops
repeat a code for a fixed number of times
for i in range(count):
code to execute
if statements and conditionals
a function that returns a true/false answer
if condition:
code
if/else statements
these statements let karel handle diffferent types of worlds
if conditions:
# code if condition is true
else:
# code to run otherwise
while loops
allows us to repeat a section of code as long as it is true
while condition:
# code to execute while condition is true
control structures
ask questions
repeat code
debugging strategies
attention to detail
even smaller syntax error could be a problem
question all your code
small errors
typos in variable names
syntax, loops, if statements
code that isn’t what you meant
mix-ups
debugging with error messages
syntax error:
runtime error:
logic error:
program doesn’t start running
program starts but then crashes
program starts, but doesn’t do what you want
algorithms
self-contained, step by step set of instructions
programs
implementation of algorithms into a computer
3 building blocks
sequencing:
iteration:
selection:
step by step instructions in the order they are given
repetition of instructions a specified number of times'
using a condition to determine which part is executed
pseudocode
writing out the algorithm in english- like code to help us figure out how to write the program
parameters
inputs into functions
paint(color[‘red’])
color_is(color[‘red’])