Error
Errors:
5 points
In this program, Karel walks down the street and picks up litter as she goes. Notice how there are two commands indented inside of the for loop!
Exploration Questions:
- What happens when you move the
take_ball()
command outside of the for loop? - What happens when you delete the last
move()
command? Why can’t you include the lastmove()
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.