Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

karel starts at street 1 and avenue 1, facing east. after calling the s…

Question

karel starts at street 1 and avenue 1, facing east. after calling the stairstep function twice, where will karel be and what direction will karel be facing? (assume this is a superkarel program and the world is 10x10 in size)
function stairstep() {
move();
turnleft();
move();
turnright();
}
street 2, avenue 2, facing north
street 3, avenue 3, facing east
street 3, avenue 3, facing west
street 4, avenue 4, facing east

Explanation:

Step1: Analyze first function call

Karel starts at Street 1, Avenue 1 facing East. In the stairStep function, move() moves 1 unit East (to Street 1, Avenue 2), turnLeft() makes it face North, move() moves 1 unit North (to Street 2, Avenue 2), turnRight() makes it face East again. So after first stairStep, Karel is at Street 2, Avenue 2 facing East.

Step2: Analyze second function call

Starting from Street 2, Avenue 2 facing East, the move() in stairStep moves it to Street 2, Avenue 3, turnLeft() makes it face North, move() moves it to Street 3, Avenue 3, turnRight() makes it face East.

Answer:

Street 3, Avenue 3, Facing East