1.18.3 Tower Builder
Question: 1.2.2 Quiz: Karel Commands
Question: 1
Which of these is a valid Karel command?
move
MOVE
move()
move(1)
Question: 2
Which one of these is NOT a command that Karel knows?
Turn Left
Turn Right
Move Forward
Put Down a Ball
Answer: move()
Turn Right
==================================================
Question: 1.2.4: Your First Karel Program
Answer: if frontisclear():
move()
if balls_present():
take_ball()
else:
move()
if frontisclear():
move()
if balls_present():
take_ball()
else:
move()
if balls_present():
take_ball()
==================================================
Question: 1.2.5: Short Stack
Answer: move()
put_ball()
put_ball()
move()
==================================================
Question: 1.3.2 More Basic Karel Quiz
Question: 1
What is a street in a Karel world?
A row
A column
A single point
Karel’s position
Question: 2
What is an avenue in a Karel world?
A row
A column
A single point
Karel’s position
Question: 3
If Karel starts at Street 1 and Avenue 3 facing East, what street (row) and avenue (column) will Karel be on after this code runs?
move()
move()
move()
turn_left()
move()
Street 1 and Avenue 3
Street 4 and Avenue 4
Street 2 and Avenue 6
Street 6 and Avenue 2
Question: 4
If Karel is facing North and the code
turn_left()
turn_left()
runs, which direction is Karel facing now?
North
South
East
West
Answer: A row
A column
Street 2 and Avenue 6
South
==================================================
Question: 1.3.4: Make a Tower
Answer: move()
turn_left()
put_ball()
move()
put_ball()
move()
put_ball()
move()
turn_left()
turn_left()
turn_left()
==================================================
Question: 1.3.5: Pyramid of Karel
Answer: put_ball()
move()
put_ball()
move()
turn_left()
put_ball()
move()
put_ball()
turn_left()
move()
put_ball()
turn_left()
turn_left()
move()
turn_left()
move()
put_ball()
turn_left()
turn_left()
turn_left()
==================================================
Question: 1.4.2 Karel Can’t Turn Right Quiz
Question: 1
How many times should Karel turn left in order to turn right?
1
2
3
4
Question: 2
What can be used to teach Karel to turn right?
Functions
Variables
Dog treats
Karel can already turn right
Answer: 3
Functions
==================================================
Question: 1.4.4: Fireman Karel
Answer: def turn_right():
turn_left()
turn_left()
turn_left()
turn_right()
move()
move()
move()
turn_left()
==================================================
Question: 1.4.5: Slide Karel
Answer: def turn_right():
turn_left()
turn_left()
turn_left()
put_ball()
move()
turn_right()
move()
put_ball()
move()
turn_left()
move()
put_ball()
==================================================
Question: 1.5.2 Functions in Karel Quiz
Question: 1
Which function will teach Karel how to spin in a circle one time?
A
def spin():
turn_right()
B
def spin():
turn_left()
turn_left()
turn_left()
turn_left()
C
def spin():
turn_left()
turn_left()
D
def spin():
move()
move()
move()
move()
A
B
C
D
Answer: B
==================================================
Question: 1.5.4: Pancakes
Answer: def make_pancakes():
put_ball()
put_ball()
put_ball()
move()
make_pancakes()
move()
move()
make_pancakes()
move()
move()
make_pancakes()
move()
==================================================
Question: 1.5.5: Backflip
Answer: def backflip():
turn_left()
turn_left()
turn_left()
turn_left()
move()
move()
move()
move()
backflip()
==================================================
Question: 1.5.6: Digging Karel
Answer: def turn_right():
turn_left()
turn_left()
turn_left()
def turn_around():
turn_left()
turn_left()
def bury_ball():
turn_right()
move()
move()
move()
put_ball()
turn_around()
move()
move()
move()
turn_right()
move()
move()
bury_ball()
move()
move()
move()
bury_ball()
move()
move()
move()
bury_ball()
move()
==================================================
Question: 1.6.2 Top Down Design and Decomposition Quiz
Question: 1
Why do we use functions in programming?
Break down our program into smaller parts
Avoid repeating code
Make our program more readable
All of the above
Question: 2
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.
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 classes to decompose the problem
Answer: All of the above
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: 1.6.4: The Two Towers
Answer: def stack():
put_ball()
turn_left()
move()
put_ball()
move()
put_ball()
turn_twice()
move()
move()
turn_left()
def turn_twice():
turn_left()
turn_left()
def turn_right():
turn_left()
turn_left()
turn_left()
move()
stack()
move()
move()
turn_left()
put_ball()
move()
put_ball()
move()
put_ball()
move()
turn_right()
==================================================
Question: 1.7.2 Commenting Your Code Quiz
Question: 1
What is a code comment?
A way to teach Karel a new word
A way to give notes to the reader to explain what your code is doing
A message to your teacher in code
A place to write whatever you want in your code
Answer: A way to give notes to the reader to explain what your code is doing
==================================================
Question: 1.7.4: The Two Towers + Comments
Answer: def stack():
put_ball()
turn_left()
move()
put_ball()
move()
put_ball()
turn_twice()
move()
move()
turn_left()
def turn_twice():
turn_left()
turn_left()
def turn_right():
turn_left()
turn_left()
turn_left()
move()
make a stack of 3 balls
stack()
move()
move()
turn_left()
starting a stack of 3 balls
put_ball()
move()
put_ball()
move()
put_ball()
move()
turn_right()
==================================================
Question: 1.8.2 Abstraction Quiz
Question: 1
Each of the following answer choices describes a basketball game.
Which answer choice describes the game with the lowest level of abstraction?
The Warriors won by 10 points.
The Warriors had an early lead, but were down by 4 at halftime. They tied it up in the 4th quarter and the game went into overtime. They won by 10 points in overtime.
First, Steph Curry jumped in the air and grabbed the ball. Then he dribbled it three times and passed it to Klay Thompson…
First, Steph Curry flexed his left and right quad muscles at the exact same time, then he flexed each muscle in his fingers…
Question: 2
Karel needs to pick up a pile of tennis balls.
Which of the following program functions solves the problem at the highest level of abstraction?
move()
move()
turn_left()
turn_left()
turn_left()
move()
take_ball()
take_ball()
move_twice()
turn_left()
turn_left()
turn_left()
move()
take_pile()
move_twice()
turn_right()
move()
take_pile()
movetopile()
take_pile()
Answer: First, Steph Curry flexed his left and right quad muscles at the exact same time, then he flexed each muscle in his fingers…
movetopile()
take_pile()
==================================================
Question: 1.9.2 Super Karel Quiz
Question: 1
What commands does SuperKarel know that regular Karel does not?
turn_left() and jump()
turn_right() and jump()
turnaround() and turnright()
turn_around() and jump()
Answer: turnaround() and turnright()
==================================================
Question: 1.9.4: The Two Towers + SuperKarel
Answer: def stack():
put_ball()
turn_left()
move()
put_ball()
move()
put_ball()
turn_around()
move()
move()
turn_left()
move()
make a stack of 3 balls
stack()
move()
move()
turn_left()
starting a stack of 3 balls
put_ball()
move()
put_ball()
move()
put_ball()
move()
turn_right()
==================================================
Question: 1.10.2 For Loops Quiz
Question: 1
What is the best way for Karel to move 10 times?
move()
move()
move()
move()
move()
move()
move()
move()
move()
move()
for i in range(10):
move()
move(10)
move10()
Answer: for i in range(10):
move()
==================================================
Question: 1.10.5: Take ‘em All
Answer: move()
for i in range(100):
take_ball()
move()
==================================================
Question: 1.10.6: Dizzy Karel
Answer: for i in range(32):
turn_left()
==================================================
Question: 1.10.7: For Loop Square
Answer: for i in range(4):
put_ball()
move()
turn_left()
==================================================
Question: 1.10.8: Lots of Hurdles
Answer: def jump_hurdle():
turn_left()
move()
turn_right()
move()
turn_right()
move()
turn_left()
for i in range(5):
move()
move()
jump_hurdle()
==================================================
Question: 1.11.2 If Statements Quiz
Question: 1
Why do we use if statements in Python?
To break out of some block of code
To do something only if a condition is true
To do something while a condition is true
To repeat something for a fixed number of times
Question: 2
Which general if statement definition is written correctly?
A
for condition: # code
B
if condition: # code
C
if i in range(COUNT): #code
D
if false: # code
A
B
C
D
Answer: To do something only if a condition is true
B
==================================================
Question: 1.11.5: Is There a Ball?
Answer: if noballspresent():
put_ball()
move()
==================================================
Question: 1.12.2 If/Else Statements Quiz
Question: 1
What does an if/else statement look like in Python?
if condition:
code
if condition:
code
else condition:
code
if condition:
code
if condition:
code
if condition:
code
else:
code
Question: 2
Why do we use if/else statements in Python?
To repeat something for a fixed number of times
To do something if a condition is true and do something else if the condition is false
To break out of some block of code
To repeat something while a condition is true
Answer: if condition:
code
else:
code
To do something if a condition is true and do something else if the condition is false
==================================================
Question: 1.12.5: Right Side Up
Answer: if facing_south():
turn_left()
if facing_west():
turn_left()
turn_left()
==================================================
Question: 1.13.2 While Loops in Karel Quiz
Question: 1
Why do we use while loops in Python?
To break out of some block of code
To do something if a condition is true
To repeat some code while a condition is true
To repeat something for a fixed number of times
Question: 2
Which general while loop definition is written correctly?
while x is true:
code
if i<5:
#code
while I in range(5):
code
while condition:
code
Answer: To repeat some code while a condition is true
while condition:
code
==================================================
Question: 1.13.4: Follow The Yellow Ball Road
Answer: while balls_present():
move()
==================================================
Question: 1.13.5: Lay Row of Tennis Balls
Answer: put_ball()
while balls_present():
move()
put_ball()
==================================================
Question: 1.13.6: Big Tower
Answer: put_ball()
if facing_west():
turn_right()
if facing_south():
turn_left()
turn_left()
if facing_east():
turn_left()
while frontisclear():
move()
put_ball()
==================================================
Question: 1.14.2 Control Structures Example Quiz
Question: 1
What do we use control structures for in Python?
Control the flow of the program; how the commands execute.
Start our Python program
Store information for later
Teach Karel new commands
Question: 2
Which of the below are examples of control structures?
(I) if
(II) if/else
(III) while
(IV) for
I only
I and II only
III and I only
I, II, III, and IV
Answer: Control the flow of the program; how the commands execute.
I, II, III, and IV
==================================================
Question: 1.14.4: Random Hurdles
Answer: def jump_hurdle():
turn_left()
move()
turn_right()
move()
turn_right()
move()
turn_left()
for i in range(13):
if frontisclear():
move()
else:
jump_hurdle()
==================================================
Question: 1.15.2 Debugging Basics
Question: 1
Will the following program move Karel one space, put down three tennis balls, then move forward and put down three more tennis balls?
def tennis_balls():
for i in range(3):
if noballspresent():
put_ball()
else: take_ball()
move()
tennis_balls()
move()
tennis_balls()
Yes, because it is using the tennis_balls() function.
No, because the tennis_balls() function is looping the wrong number of times.
Yes, because the move() command is being called outside of the function.
No, because the tennis_balls() function has an incorrect if/else statement.
Question: 2
The following code contains an error. What line is it on?
1 def turn_right():
2 turn_left()
3 turn_left()
4 turn_Left()
5
6 move()
7 turn_left()
8 move()
9 turn_right()
10 move()
11 move()
line 3
line 4
line 5
line 7
Answer: No, because the tennis_balls() function has an incorrect if/else statement.
line 4
==================================================
Question: 1.15.6 Debugging with Error Messages
Question: 1
Which of the following is an example of a ‘runtime error’?
Karel crashing into a wall
II. Leaving a colon off the end of a function definition
III. Using the wrong syntax in an if/else statement
IV. Not closing all open parenthesis
I
I and III
II and IV
I-IV, all
Question: 2
If the following program is supposed to put down three tennis balls, where is the logic error?
1 def placethreeball():
2 for i in range(4):
3 put_ball()
4
5 placeThreeBalls()
Line 1
Line 2
Line 3
Line 5
Answer: I
Line 2
==================================================
Question: 1.16.2 Quiz: Which Control Structure?
Question: 1
You need to write a program where Karel will take a ball if there is a ball present, otherwise Karel should put down a ball.
Which control structure do you need to use?
For Loop
While Loop
If Statement
If/Else statement
None of these
Question: 2
You need to write a program that has Karel move 6 times and then put a ball.
Which control structure do you need to use?
For loop
While Loop
If Statement
If/Else statement
None of these
Question: 3
You need to write a program that has Karel take all the tennis balls if there are any where Karel is standing.
Karel should end up with no tennis balls on that spot.
Which control structure do you need to use?
For Loop
While Loop
If Statement
If/Else Statement
None of these
Question: 4
You need to write a program that has Karel put down a tennis ball if the world has dimensions of 1x1.
Which control structure do you need to use?
For Loop
While Loop
If Statement
If/Else statement
None of these
Question: 5
You need to write a program that has Karel move one time if the front is clear, but if it isn’t clear, Karel will do nothing.
Which control structure do you need to use?
For Loop
While Loop
If Statement
If/Else statement
None of these
Answer: If/Else statement
For loop
While Loop
If Statement
If Statement
==================================================
Question: 1.16.6: Decorate the Fence
Answer: while frontisclear():
move()
def stack():
if frontisblocked():
put_ball()
turn_left()
move()
turn_right()
else:
turn_left()
move()
turn_right()
for i in range(9):
stack()
put_ball()
turn_left()
==================================================
Question: 1.17.2 Ultra Karel Quiz
Question: 1
Which of the following is the correct way to have Karel paint a red square using the paint function?
paint_red()
paint_color.red()
paint(color[“red”])
paint(color[red])
Question: 2
What is a parameter?
Another name for a function
Input into a function
Output from a function
A function that paints a square in Karel’s grid world
Answer: paint(color[“red”])
Input into a function
==================================================
Question: 1.17.5: Invert Colors
Answer: def invert_color():
if color_is(color[“red”]):
paint(color[“blue”])
move()
if color_is(color[“blue”]):
paint(color[“red”]
move()
while frontisclear():
invert_color()
if frontisblocked():
if color_is(color[“red”]):
paint(color[“blue”])
else:
paint(color[“red”])
==================================================
Question: 1.17.6: Checkerboard Karel
Answer: for i in range(8):
while frontisclear():
paint(color[‘black’])
move()
paint(color[‘red’])
if frontisclear():
move()
while notfacingnorth():
turn_left()
if frontisclear():
move()
if rightisblocked():
turn_left()
if leftisblocked():
turn_right()
turn_around()
while frontisclear():
move()
turn_left()
==================================================
Question: 1.18.1: Fetch
Answer: turn_left()
for i in range(4):
move()
turn_right()
move()
move()
take_ball()
turn_left()
turn_left()
move()
move()
for i in range(3):
turn_right()
for i in range(4):
move()
turn_left()
put_ball()
==================================================
Question: 1.18.2: Racing Karel
Answer: for i in range(32):
while frontisclear():
move()
while frontisblocked():
turn_left()
put_ball()
==================================================
Question: 1.18.3: Tower Builder
Answer: def tower():
turn_left()
put_ball()
move()
put_ball()
move()
put_ball()
turn_around()
move()
move()
turn_left()
tower()
while frontisclear():
move()
if frontisclear():
move()
tower()
==================================================
Question: 1.18.4: Super Cleanup Karel
Answer: for i in range(30):
while frontisclear():
if balls_present():
take_ball()
move()
else:
move()
while notfacingnorth():
turn_left()
if balls_present():
take_ball()
if frontisclear():
move()
if rightisblocked():
turn_left()
if leftisblocked():
turn_right()
==================================================
Question: 1.18.5: Double Tennis Balls
Answer: move()
while balls_present():
take_ball()
move()
put_ball()
put_ball()
turn_around()
move()
turn_around()
move()
turn_around()
while balls_present():
take_ball()
move()
put_ball()
turn_around()
move()
turn_around()
move()
move()
turn_around()
==================================================