Font size
WorksheetsFinal/Midterm Review
Total questions: 15
Worksheet time: 15mins
In order to ask the user for input and store the result as a string, you should use the function called _
(a)
Most lines of code must end with a
int
string
semicolon
float
A(n) _ variable can either take the value true or false.
(a)
A(n) _ is a series of steps or instructions that describe how to solve a problem.
Algorithm
readInt
Karel
float
A(n) (a) variable stores whole number
Suppose you are writing a function that computes the area of a soccer field. Which of the following comments would be the best to use?
//This is a function
// This function computes the area
//Computes and returns the are of a football field using the parameters of height and width
This function doesnt need a comment
The following if statement should check that an object will fit on the screen. The variables height and width store the height and width of the object. The variables screenHeight and screenWidth store the dimensions of the screen.
Which of the following pairs correctly fill in the condition for the if statement below?
(height < screenHeight) && (width < screenWidth)
(height < screenHeight) || (width < screenWidth)
(height > screenHeight) || (width > screenWidth)
(height > screenHeight) && (width > screenWidth)
In which of the following scenarios would it be best to use a for loop?
When you need to stop looping based on input from the user
When you need to check that a user’s input is valid
When you need to be able to use the block of code in many places in your program
When you want to ask the user for 10 numbers
In which of the following scenarios would it be best to use a while loop?
When you need to loop as long as the user inputs even numbers
When you need to get and store the user’s age
When you need to find the average of 12 numbers
When you need to change the color of one rectangle
Why do programmers use variables?
It allows the programmer to reuse multiple lines of code
Because they are lazy and don’t want to write out equations every time
To store values to easily reuse later and make code easier to read and understand
They are a way to document functions
Which of the following while loops will make Karel move until a wall is in the way?
while(noBallsPresent()){
move();
}
while(facingEast()){
move();
}
while(frontIsBlocked()){
move();
}
while(frontIsClear()){
move();
}
Which of the following pairs of keywords correctly fills in the code below?
while,if
for, if
while,else
if, else
Which of the following choices is a valid and useful variable name?
myVariable
joes___variable
minNum
2nd Number
What is Top Down Design?
Working from the top of your program and coding down to the bottom
Starting with the biggest problem and then working down to solve the more specific problems
Implementing all of the functions first, then putting them together in the start function
Starting with the most specific problems and then working up to solve the big problem
What would be the output of the following program?
