64.4k views
4 votes
Assume that Karel is on a corner with either one or two beepers. Write a new instruction that commands him to face north if he is started on a corner with one beeper and to face south if he is started on a corner with two beepers. Besides facing him in the required direction, after Karel has executed this instruction there must be no beepers left on his corner. Name this instruction find-next-direction.

1 Answer

1 vote

Final answer:

The new instruction to make Karel face north or south depending on the number of beepers on the corner.

Step-by-step explanation:

The new instruction that commands Karel to face north if he is started on a corner with one beeper and to face south if he is started on a corner with two beepers can be called find-next-direction. To implement this instruction, you can use an if-else statement to check the number of beepers on Karel's corner. If there is one beeper, you can use the turnNorth() command to make Karel face north. If there are two beepers, you can use the turnSouth() command to make Karel face south.

User Bones
by
7.3k points