QUESTION IMAGE
Question
question 16
in the following code, taken from the cleanup karel example, what is the purpose of if statement #2?
a karel program has karel walk down the
row and clean up all of the tennis balls
in the way.
while front_is_clear():
if statement #1
if balls_present():
take_ball()
move()
if statement #2
if balls_present():
take_ball()
to move the last time
to pick up the ball that is in the last spot
to pick up the ball that is in the last spot, if there is one
to take the ball from all of the positions that have a ball on them
question 17
in the following code, what would be a good post - condition to write?
precondition: karel is on a spot with a tennis ball facing east.
do something here
put_art_on_top()
turn_left()
move()
move_right()
karel is on a spot with a tennis ball facing north
karel ends one spot above a tennis ball facing east.
karel is in the same position but on top of a ball
karel is facing east.
For Question 16, the if statement checks if a ball is present and then takes the ball. It's conditional on the ball being in the spot, so it's to pick up the ball that is in the last spot, if there is one. For Question 17, starting with the pre - condition that Karel is on a spot with a tennis ball facing East, after turning left and moving, the post - condition would be that Karel is facing North.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
Question 16: C. To pick up the ball that is in the last spot, if there is one
Question 17: A. Karel is on a spot with a tennis ball facing north