QUESTION IMAGE
Question
question 1
you need to write a program that has karel put down a tennis ball if karel is not able to move forward in the direction they are currently facing.
which control structure do you need to use?
for loop
while loop
if statement
if/else statement
none of these
An If Statement is used to execute code when a certain condition is met. Here, the condition is "Karel is not able to move forward in the direction they are currently facing", and when this condition is true, Karel should put down a tennis ball. Loops (For and While) are used for repetitive tasks, and an If/Else statement is used when there are two - alternative actions based on a condition. Since only one action (putting down a ball) is needed when the condition is true, an If Statement suffices.
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
C. If Statement