~Karel Challenges Unit Test Answers~

Ace your homework & exams now with Quizwiz!

Question: 11 What is the proper format for a single line comment in Karel?

// This is a comment

Question: 14 Say Karel is on a location with one tennis ball. After the following code runs, how many tennis balls will there be at that location?

1

Question: 9 How many total times will Karel move in this program?

6

Question: 16 Why does a programmer indent their code?

All of the above

Question: 4 Why do we use functions in Karel programs?

All of the above

Question: 7 In this code, how many times is the dance function called and how many times is it defined?

Called 3 times, defined 1 time

Question: 17 How can we teach Karel new commands?

Define a new function

Question: 18 Say you want to write a program to have Karel put down 300 tennis balls. Which control structure would you use?

For loop

Question: 10 What is wrong with this for loop?

I and II

Question: 24 In the following code, what would be a good Postcondition to write?

Karel ends one spot above a tennis ball facing East.

Question: 12 What does the mystery function do?

Karel moves until it is on a ball

Question: 19 Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs?

Karel will crash into a wall

Question: 5 If Karel starts at Street 1 and Avenue 1, facing East, where will Karel be, and what direction will Karel be facing after running the following code? (Assume the world is 10x10 in size)

Street 1, Avenue 3, Facing North

Question: 6 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)

Street 3, Avenue 3, Facing East

Question: 8 What's wrong with this code?

The go function has been defined twice

Question: 2 What makes the following command an invalid Karel command?

The l should be a capital L

Question: 20 Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs?

This code won't run because of a syntax error

Question: 23 In the following code below from the Cleanup Karel example, what is the purpose of If Statement #2?

To pick up the ball that is in the last spot, if there is one

Question: 25 What is the purpose of using a for loop in code?

To repeat something a fixed number of times

Question: 21 What is top down design?

Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.

Question: 22 How can we improve the following program?

Use a for loop to repeat the move command

Question: 15 What condition should be used in this while loop to get Karel to pick up all the tennis balls on the current location?

ballsPresent

Question: 3 Which of the following is the correct way to define a turnRight function in Karel?

function turnRight() { turnLeft(); turnLeft(); turnLeft(); }

Question: 1 Which of the following commands is a valid Karel command?

move();

Question: 13 Which of the following is not a valid condition to go in an if statement for Karel?

turnLeft()


Related study sets

Subjective vs Objective Statements

View Set

Chapter 11: Learning, Memory, and Amnesia

View Set

HPE 101 Ch 15 Health Care Choices

View Set