Font size
WorksheetsKarel Programming
Total questions: 39
Worksheet time: 23mins
A set of steps or rules to follow to solve a particular problem.
algorithm
Decomposition
Function
control structures
The process of breaking down your code into smaller parts (more functions)
Decomposition
Indentation
lowerCamelCase
Start Function
Teaching the computer a new command. Used to explain what a program should do when receiving that command.
Defining a Function
Calling a Function
Start Function
Readability
Used to teach Karel a new word or command. Using these allows programs to be broken down into smaller pieces and makes it easier to understand.
Functions
Control Structures
algorithms
Indentation
Choose TWO: Ways (using syntax) that you can write comments?
multi-line
"""/*
*
*/"""
single line
//
multi-line
**
single line
#
Which of the following commands is a valid Karel command?
move
move( )
move( );
move;
Which of the following is the correct way to define a turnRight function in Karel?
function turnRight() {
turnLeft();
turnLeft();
turnLeft();
}
function turnRight() {
turnRight();
turnRight();
turnRight();
}
function turnRight {
turnLeft();
turnLeft();
turnLeft();
}
turnRight function() {
turnLeft();
turnLeft();
turnLeft();
}
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
For loop
Nested while loop
What is top down design?
Top down design is a way to use loops and if statements to decompose the problem
Top down design is a way of designing your programs starting with the individual commands first
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
How can we improve the following program?
function start() {
move();
move();
move();
move();
move();
move();
move();
move();
move();
}
Break down this program into more functions
Use a for loop to repeat the move command
Use a while loop to repeat the move command
Fix the indentation of this program
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
To repeat something a fixed number of times
To make programs run faster
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
this code won’t run because of a syntax error
Karel will crash into a wall
What’s wrong with this code?
function start() {
move();
go();
go();
}
function go() {
move();
move();
}
function go() {
move();
move();
}
The go function is called twice
The go function has a syntax error
The go function has been defined twice
go is not a command that Karel understands
In this code, how many times is the dance function called and how many times is it defined?
function start() {
move();
dance();
move();
move();
turnLeft();
dance();
dance();
}
function dance() {
turnLeft();
move();
turnLeft();
turnLeft();
move();
turnLeft();
}
Called 1 time, defined 1 time
Called 1 time, defined 3 times
Called 3 times, defined 1 time
Called 3 times, defined 3 times
A message in your code that explains what is going on -- not apart of the executing of the program.
Decomposition
Comment
Condition
Control Structure
What is conditional statement in programming?
A conditional statement in programming is a statement that is used to perform mathematical calculations.
A conditional statement in programming is a statement that is used to declare variables.
A conditional statement in programming is a statement that performs different actions based on whether a certain condition is true or false.
A conditional statement in programming is a statement that performs the same actions regardless of whether a certain condition is true or false.
What is the importance of indentation in programming?
Indentation has no impact on code readability.
Indentation improves code readability and maintainability.
Indentation makes the code more difficult to understand.
Indentation is only necessary for aesthetic purposes.
What is the purpose of an if statement in programming?
An if statement in programming is used to perform mathematical calculations.
An if statement in programming is used to declare variables.
An if statement in programming is used to perform different actions based on whether a certain condition is true or false.
An if statement in programming is used to perform the same actions regardless of whether a certain condition is true or false.
Each Karel command ends with a () and a ;.
True
False
What is decomposition?
Searches the computer's memory for data
Repeats a program
Getting small part of a problem and adding them together
Breaking down a complex problem
A_______is a sequence of instructions that is continually repeated until a certain condition is reached.
Pixels
Sequence
Loop
Algorithm
How does an else statement differ from an if statement?
It always executes, regardless of conditions
It executes when the 'if condition' is true
It executes when the 'if condition' is false
It can only be used with numbers, not booleans
This code:
putBall();
move();
putBall();
put 2 balls in the same place and then move one place?
True
False
The code in the picture will move Karel in a square.
True
False
Which code will put Karel in the position shown in second world?
putBall(); putBall(); move(); move();
move(); putBall(); move(); putBall();
putBall(); move(); putBall(); move();
move(); putBall(); putBall(); move();
Precondition: Karel is in location (1,1) facing east.
Which code below will put Karel in the position shown in picture?
move(); Move(); turnLeft(); move();
move; move(); turnLeft; move();
move(); move(); TurnLeft(); Move();
move(); move(); turnLeft(); move();
Which code will put Karel in the position shown in second world?
putBall(); putBall(); move(); move();
move(); putBall(); move(); putBall();
putBall(); move(); putBall(); move();
move(); putBall(); putBall(); move();
Is this function written correctly?
True
False
What is the name of this function?
function
spin()
3 turnLeft();
spin();
How many times should Karel turn left in order to turn right?
1
2
3
4
What can be used to teach Karel to turn right?
Functions
Variables
Dog Treats
Karel can already turn right
Karel needs to move forward, then turn left, then move forward, then put down a ball.
move();
turnLeft();
move();
putBall();
move();
turnLeft();
move();
takeBall();
move();
turnLeft();
move();
move();
move();
turnLeft()
move();
putBall()
Karel needs to take the ball that is already present on her initial space then move forward four spaces and place the ball. Then turn Left
takeBall();
move 2 times ();
move 2 times ();
putBall();
turnLeft
takeBall();
move();
move();
move();
move();
putBall();
turnLeft();
takeBall();
move();
move();
putBall();
TurnLeft{};
takeBall();
move(4);
putBall();
turnLeft():
