Error
Errors:
5 points
This program has Karel walk to the stack of litter, pick it up, and then continue on her way. Notice the use of the for loop to make picking up the litter faster!
Exploration Questions:
- What happens when you change the number in the for loop?
- What happens when you un-indent the
take_ball()
command? - What happens if you move the
move()
command inside the for loop?
Ending World
Karel's Built in Commands
Karel Commands
|
|
|
|
|
UltraKarel
UltraKarel Commands
|
UltraKarel Conditions
|
|
Color
Random
Functions
Writing a Function
Writing a function is like teaching karel a new word.
Naming Functions: You can name your functions whatever you want, but you can't have spaces in the function name.
Remember that commands in functions must be indented one level
Calling a Function
You call a function to tell the computer to actually carry out the new command.
Conditional Statements
Remember that comands in conditional statements must be indented one level.If statements
If/Else statements
Example of if statements
Karel Conditions
Don't forget the()
at the end!
|
|
Loops
Remember that commands in a loop statement must be indented one level.While Loops
Example of while loops
For Loops
Example of for loops
You can have multiple statements or function calls in a for loop.
Use for-loops when you want to repeat something a fixed number of times.
Use while-loops when you want to repeat something as long as a condition is true.