1/46
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
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
move()
Turn Right
1.2.4: Your First Karel Program
if front_is_clear():
move()
if balls_present():
take_ball()
else:
move()
if front_is_clear():
move()
if balls_present():
take_ball()
else:
move()
if balls_present():
take_ball()
1.2.5: Short Stack
move()
put_ball()
put_ball()
move()
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
A row
A column
Street 2 and Avenue 6
South
1.3.4: Make a Tower
move()
turn_left()
put_ball()
move()
put_ball()
move()
put_ball()
move()
turn_left()
turn_left()
turn_left()
1.3.5: Pyramid of Karel
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()
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
3
Functions
1.4.4: Fireman Karel
def turn_right():
turn_left()
turn_left()
turn_left()
turn_right()
move()
move()
move()
turn_left()
1.4.5: Slide Karel
def turn_right():
turn_left()
turn_left()
turn_left()
put_ball()
move()
turn_right()
move()
put_ball()
move()
turn_left()
move()
put_ball()
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
B
1.5.4: Pancakes
def make_pancakes():
put_ball()
put_ball()
put_ball()
move()
make_pancakes()
move()
move()
make_pancakes()
move()
move()
make_pancakes()
move()
1.5.5: Backflip
def backflip():
turn_left()
turn_left()
turn_left()
turn_left()
move()
move()
move()
move()
backflip()
1.5.6: Digging Karel
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()
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
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.
1.6.4: The Two Towers
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()
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
A way to give notes to the reader to explain what your code is doing
1.7.4: The Two Towers + Comments
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()
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()
move_to_pile()
take_pile()
First, Steph Curry flexed his left and right quad muscles at the exact same time, then he flexed each muscle in his fingers...
move_to_pile()
take_pile()
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()
turn_around() and turn_right()
turn_around() and jump()
turn_around() and turn_right()
1.9.4: The Two Towers + SuperKarel
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()
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()
for i in range(10):
move()
1.10.5: Take 'em All
move()
for i in range(100):
take_ball()
move()
1.10.6: Dizzy Karel
for i in range(32):
turn_left()
1.10.7: For Loop Square
for i in range(4):
put_ball()
move()
turn_left()
1.10.8: Lots of Hurdles
def jump_hurdle():
turn_left()
move()
turn_right()
move()
turn_right()
move()
turn_left()
for i in range(5):
move()
move()
jump_hurdle()
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
To do something only if a condition is true
B
1.11.5: Is There a Ball?
if no_balls_present():
put_ball()
move()
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
if condition:
# code
else:
# code
To do something if a condition is true and do something else if the condition is false
1.12.5: Right Side Up
if facing_south():
turn_left()
if facing_west():
turn_left()
turn_left()
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
To repeat some code while a condition is true
while condition:
# code
1.13.4: Follow The Yellow Ball Road
while balls_present():
move()
1.13.5: Lay Row of Tennis Balls
put_ball()
while balls_present():
move()
put_ball()
1.13.6: Big Tower
put_ball()
if facing_west():
turn_right()
if facing_south():
turn_left()
turn_left()
if facing_east():
turn_left()
while front_is_clear():
move()
put_ball()
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
Control the flow of the program; how the commands execute.
I, II, III, and IV
1.14.4: Random Hurdles
def jump_hurdle():
turn_left()
move()
turn_right()
move()
turn_right()
move()
turn_left()
for i in range(13):
if front_is_clear():
move()
else:
jump_hurdle()
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 no_balls_present():
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
No, because the tennis_balls() function has an incorrect if/else statement.
line 4
1.15.6 Debugging with Error Messages
Question: 1
Which of the following is an example of a 'runtime error'?
I. 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 place_three_ball():
2 for i in range(4):
3 put_ball()
4
5 placeThreeBalls()
Line 1
Line 2
Line 3
Line 5
I
Line 2
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
If/Else statement
For loop
While Loop
If Statement
If Statement
1.16.6: Decorate the Fence
while front_is_clear():
move()
def stack():
if front_is_blocked():
put_ball()
turn_left()
move()
turn_right()
else:
turn_left()
move()
turn_right()
for i in range(9):
stack()
put_ball()
turn_left()
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
paint(color["red"])
Input into a function
1.17.5: Invert Colors
def invert_color():
if color_is(color["red"]):
paint(color["blue"])
move()
if color_is(color["blue"]):
paint(color["red"]
move()
while front_is_clear():
invert_color()
if front_is_blocked():
if color_is(color["red"]):
paint(color["blue"])
else:
paint(color["red"])
1.17.6: Checkerboard Karel
for i in range(8):
while front_is_clear():
paint(color['black'])
move()
paint(color['red'])
if front_is_clear():
move()
while not_facing_north():
turn_left()
if front_is_clear():
move()
if right_is_blocked():
turn_left()
if left_is_blocked():
turn_right()
turn_around()
while front_is_clear():
move()
turn_left()
1.18.1: Fetch
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()
1.18.2: Racing Karel
for i in range(32):
while front_is_clear():
move()
while front_is_blocked():
turn_left()
put_ball()
1.18.3: Tower Builder
def tower():
turn_left()
put_ball()
move()
put_ball()
move()
put_ball()
turn_around()
move()
move()
turn_left()
tower()
while front_is_clear():
move()
if front_is_clear():
move()
tower()
1.18.4: Super Cleanup Karel
for i in range(30):
while front_is_clear():
if balls_present():
take_ball()
move()
else:
move()
while not_facing_north():
turn_left()
if balls_present():
take_ball()
if front_is_clear():
move()
if right_is_blocked():
turn_left()
if left_is_blocked():
turn_right()
1.18.5: Double Tennis Balls
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()