Question: 1
What’s wrong with this code?
def go():
move()
move()
def go():
move()
move()
move()
go()
go()
The go
function is called twice
The go
function has a syntax error
Correct Answer
The go
function has been defined twice
go
is not a command that Karel understands
Correct
Question: 2
How many total times will Karel move in this program?
move()
for i in range(5):
move()
put_ball()
1
5
Correct Answer
6
7
Correct
Question: 3
What is wrong with this for loop?
for i in range = 5;
move()
A. The for loop uses a semicolon(;
) instead of colon(:
)
B. It should say range(5)
instead of range = 5
A
B
Correct Answer
A and B
The for loop is correct
Correct
Question: 4
What is the proper format for a single line comment in Karel?
Correct Answer
# This is a comment
// This is a comment
/* This is a comment
This is a comment
Correct
Question: 5
What does the mystery
function do?
def mystery():
while no_balls_present():
move()
Correct Answer
Karel moves until it is on a ball
Karel moves once if there is no ball present
Karel moves until it puts down a ball
Karel checks if there is no ball on the current spot and then moves once
Correct
Question: 6
Which of the following is not a valid condition to go in an if statement for Karel?
balls_present()
front_is_clear()
left_is_blocked()
Correct Answer
turn_left()
Correct
Question: 7
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?
for i in range(3):
if balls_present():
take_ball()
else:
put_ball()
put_ball()
0
Correct Answer
1
2
6
Correct
Question: 8
What condition should be used in this while loop to get Karel to pick up all the tennis balls on the current location?
while ________ :
take_ball()
no_balls_present()
Correct Answer
balls_present()
front_is_clear()
take_ball()
Correct
Question: 9
Why does a programmer indent their code?
Helps show the structure of the code.
Easier for other people to understand.
In Python, it is used to help determine what parts of a code are included in a code block, such as an if statement or for loop.
Correct Answer
All of the above
Correct
Question: 10
How can we teach Karel new commands?
For loop
While loop
Correct Answer
Define a new function
The main function
Correct
Question: 11
Say you want to write a program to have Karel put down 300 tennis balls. Which control structure would you use?
If statement
While loop
Correct Answer
For loop
Nested while loop
Correct
Question: 12
Super Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs?
move()
move()
turn_right()
move()
Karel ends on street 1, avenue 3
Karel ends on street 2, avenue 3
This code won’t run because of a syntax error
Correct Answer
Karel will crash into a wall
Correct
Question: 13
Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs?
move()
putball()
move()
move()
move()
move()
move()
Karel will end on Street 1, Avenue 2
Karel will end on Street 1, Avenue 7
Correct Answer
This code won’t run because of a syntax error
Karel will crash into a wall
Correct
Question: 14
What is top down design?
Correct Answer
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.
Top down design is a way that you can create designs on a computer to put on a web page
Top down design is a way of designing your programs starting with the individual commands first
Top down design is a way to use loops and if statements to decompose the problem
Correct
Question: 15
How can we improve the following program?
move()
move()
move()
move()
move()
move()
move()
move()
move()
Break down this program into more functions
Correct Answer
Use a for loop to repeat the move
command
Use a while loop to repeat the move
command
Fix the indentation of this program
Correct
Question: 16
In the following code below from the Cleanup Karel example, what is the purpose of If Statement #2?
# This program has Karel walk down the
# row and clean up all of the tennis balls
# on 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
Correct Answer
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
Correct
Question: 17
In the following code, what would be a good Postcondition to write?
"""
Precondition: Karel is on a spot with a tennis ball facing East
* Postcondition: ...
"""
def get_on_top():
turn_left()
move()
turn_right()
Karel is on a spot with a tennis ball facing north
Correct Answer
Karel ends one spot above a tennis ball facing East.
Karel is on the same position but on top of a ball.
Karel is facing East.
Correct
Question: 18
What is the purpose of using a for loop in code?
To do something if a condition is true
To do something while a condition is true
Correct Answer
To repeat something a fixed number of times
To make programs run faster
Correct
Question: 19
Which of the following commands is a valid Karel command?
move
move;
Correct Answer
move()
move();
Correct
Question: 20
What makes the following command an invalid Karel command?
turn_Left()
It should end in semicolon
Correct Answer
The L
should be a lower l
It should start with a capital T
This command is correct
Correct
Question: 21
Which of the following is the correct way to define a turn_right
function in Karel?
Correct Answer
def turn_right():
turn_left()
turn_left()
turn_left()
def turn_right(): turn_right() turn_right() turn_right()
def turn_right: turn_left() turn_left() turn_left()
function turn_right(): turn_left() turn_left() turn_left()
Correct
Question: 22
Why do we use functions in Karel programs?
Break down our program into smaller parts
Avoid repeating code
Make our program more readable
Correct Answer
All of the above
Correct
Question: 23
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)
move()
turn_left()
put_ball()
turn_left()
turn_left()
turn_left()
move()
turn_left()
Street 3, Avenue 1, Facing North
Street 1, Avenue 4, Facing North
Street 1, Avenue 3, Facing South
Correct Answer
Street 1, Avenue 3, Facing North
Correct
Question: 24
Karel starts at Street 1 and Avenue 1, facing East. After calling the stair_step
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)
def stair_step():
move()
turn_left()
move()
turn_right()
Street 2, Avenue 2, Facing North
Correct Answer
Street 3, Avenue 3, Facing East
Street 3, Avenue 3, Facing West
Street 4, Avenue 4, Facing East
Correct
Question: 25
In this code, how many times is the dance
function called and how many times is it defined?
def dance():
turn_left()
move()
turn_left()
turn_left()
move()
turn_left()
move()
dance()
move()
move()
turn_left()
dance()
dance()
Called 1 time, defined 1 time
Called 1 time, defined 3 times
Correct Answer
Called 3 times, defined 1 time
Called 3 times, defined 3 times