Karel is like a robot / remote control car with a small set of commands! (this is on purpose):
Functions are a way to define a set of steps into a logical unit.
def function_name():
# Some function code goes here
# Turning left three times goes right!
def turn_right():
turn_left()
turn_left()
turn_left()
A for loop runs for a set number of times
def turn_right():
for i in range(3):
turn_left()
A while loop runs until a condition is no longer true -- CAUTION! that could mean forever!
def move_to_wall():
while front_is_clear():
move()
An if statement executes if the condition is true
def safe_move():
if front_is_clear():
move()
Countries around the world are dispatching hospital-building robots to make sure anyone who gets sick can be treated. They have decided to enlist Karel robots, and your job is to program those robots.
Beepers are piles of supplies that tell us where to build each hospital
Karel should move along this row to find each pile of supplies
The hospital buildings are built of a 3 by 2 rectangle of beepers:
When Karel encounters a pile of supplies, that's where the building starts:
Starting with this world we should end up with this final result: