Which of the following is a valid variable assignment in pseudocode?
A) x ← 5
B) 5 ← x
C) DISPLAY x = 5
D) SET 5 TO x
What is (A): x ← 5
What does an IF statement do?
A) Test a condition
B) Repeat code
What is (A): Test a Condition
What is a function used for?
A) Reuse code
B) Repeat loops
C) Store data
D) Define variables
What is (A): Reuse Code
What is the first element in the list list ← [5, 6, 7]?
A) 5
B) 6
C) 7
D) 1
What is (A): 5
What does true AND false evaluate to?
A) true
B) false
C) Error
D) null
What is (B): False
Which of the following is a benefit of using a list as a data abstraction in a program?
A. Lists often allow their size to be easily updated to hold as many data values as needed.
B. Lists convert all elements to strings so that they can be inspected character-by-character.
C. Lists prevent duplicate data values from appearing in the list.
D. Lists are used to store all input data so that there is a running record of all user input.
What is (A): Lists often allow their size to be easily updated to hold as many data values as needed.
Predict the output:
A) Pass
B) Fail
C) Error
D) 10
What is (A): Pass
What does this display?
A) 20
B) 25
C) 10
D) 15
What is (A): 20
Consider the following code segment.
firstList ←← ["guitar", "drums", "bass"]
secondList ←← ["flute", "violin"]
thirdList ←← [ ]
thirdList ←← firstList
firstList ←← secondList
secondList ←← thirdList
What are the contents of secondList after the code segment is executed?
A [ ]
B. ["guitar", "drums", "bass"]
C. ["flute", "violin"]
D. ["flute", "violin", "guitar", "drums", "bass"]
What is (B): ["guitar", "drums", "bass"]
If a list contains n items, how many comparisons would a linear search make in the worst case?
A) 1
B) log n
C) n
D) n²
What is (C): n
What is the value of x after executing the following code?
A) 3
B) 4
C) 7
D) Error
What is (C): 7
What is the result of
What is: Yes
Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case.
A student is writing a program to model different real-world events using simulations. Which of the following simulations will generate a result that would best be stored using a Boolean variable?
A. A simulation of flipping a fair coin
B. A simulation of rolling a fair die (with sides numbered 1 through 6)
C. A simulation of the temperature in a location over time
D. A simulation of traffic patterns on a road
What is (A): A simulation of flipping a fair coin
What does APPEND(list, 10) do?
A) Adds 10 to the end of the list
B) Removes 10 from the list
C) Replaces the first element with 10
D) Sorts the list
What is (A): Adds 10 to the end of the list
To attend a particular camp, a student must be either at least 13 years old or in grade 9 or higher, but must not yet be 18 years old. Let age represent a student’s age and let grade represent the student’s grade level. Which of the following expressions evaluates to true if the student is eligible to attend the camp and evaluates to false otherwise?
ResponsesA
((age ≥ 13) OR (grade ≥ 9)) AND (age ≤ 18)
B
((age ≥ 13) OR (grade ≥ 9)) AND (age < 18)
C
((age ≥ 13) OR (grade ≥ 9)) OR (age ≤ 18)
D
((age ≥ 13) OR (grade ≥ 9)) OR (age < 18)
What is (B): ((age ≥ 13) OR (grade ≥ 9)) AND (age < 18)
Study the code segment below. Values of x and y will be displayed multiple times during the
running of the program. From the list of possible outputs, choose two of the outputs that are
impossible for this code to produce.
x ← 0
REPEAT_UNTIL( x = 3 )
y ← 0
x ← x+1
REPEAT_UNTIL ( y = 3 ){
y ← y+1
DISPLAY( x + ", " + y)
}
}
What is
- 0,0
- 2,4
A group of programming instructions. They're also known as methods or functions, depending on the programming language. You can use a procedure to use the same set of instructions, again and again, without having to rewrite it into your code.
What is a procedure
A teacher is writing a code segment that will use variables to represent a student’s name and whether or not the student is currently absent. Which of the following variables are most appropriate for the code segment?
A. A string variable named s and a Boolean variable named a
B. A string variable named s and a numeric variable named n
C. A string variable named studentName and a Boolean variable named isAbsent
D. A string variable named studentName and a numeric variable named numAbsences
What is (C): A string variable named studentName and a Boolean variable named isAbsent
Tiffany is writing a program to help manage a bake sale. She writes the following code which
prompts the user to enter the total number of items a person is buying and then a loop repeatedly
prompts for the cost of each item. She wrote the code but there is a problem: it runs in an infinite
loop. How can Tiffany change her code so it doesn't loop forever?
0 var numItems = promptNum("How many items?");
1 var total = 0;
2 while (numItems > 0){
3 total = total + promptNum("Enter next item price");
4 }
5 console.log("The total is" + total);
What is Add after line 3: numItems = numItems - 1;
To qualify for a particular scholarship, a student must have an overall grade point average of 3.0 or above and must have a science grade point average of over 3.2. Let overallGPA represent a student’s overall grade point average and let scienceGPA represent the student’s science grade point average. Which of the following expressions evaluates to true if the student is eligible for the scholarship and evaluates to false otherwise?
ResponsesA
(overallGPA > 3.0) AND (scienceGPA > 3.2)
B
(overallGPA > 3.0) AND (scienceGPA ≥ 3.2)
C
(overallGPA ≥ 3.0) AND (scienceGPA > 3.2)
D
(overallGPA ≥ 3.0) AND (scienceGPA ≥ 3.2)
What is (C): (overallGPA ≥ 3.0) AND (scienceGPA > 3.2)
A teacher is writing a code segment that will use variables to represent a student’s name and whether or not the student is currently absent. Which of the following variables are most appropriate for the code segment?
A. A string variable named s and a Boolean variable named a
B. A string variable named s and a numeric variable named n
C. A string variable named studentName and a Boolean variable named isAbsent
D. A string variable named studentName and a numeric variable named numAbsences
What is (C): A string variable named studentName and a Boolean variable named isAbsent
Assume that the Boolean variable hot is assigned the value true and the Boolean variable humid is assigned the value false. Which of the following will display the value true ?
Select two answers. ("DISPLAY" is indented)
A. IF hot
DISPLAY hot AND humid
B. IF NOT hot
DISPLAY hot OR humid
C. IF hot OR humid
DISPLAY hot
D. IF hot AND humid
DISPLAY hot
What is:
B. IF NOT hot
DISPLAY hot OR humid
C. IF hot OR humid
DISPLAY hot
Which statement correctly calls a function named addNums with 2 and 3?
A) addNums(2, 3)
B) CALL 2, 3 TO addNums
C) addNums = 2 + 3
D) FUNCTION addNums(2, 3)
What is (A): addNums(2, 3)
Which code sums values in a list?
A) It adds up all values
B) It multiplies values
C) It subtracts values
D) It divides values
What is (A): It adds up all values
A programmer wants to determine whether a score is within 10 points of a given target. For example, if the target is 50, then the scores 40, 44, 50, 58, and 60 are all within 10 points of the target, while 38 and 61 are not.
Which of the following Boolean expressions will evaluate to true if and only if score is within 10 points of target ?
A. (score ≤ target + 10) AND (target + 10 ≤ score)
B. (target + 10 ≤ score) AND (score ≤ target - 10)
C. (score ≤ target - 10) AND (score ≤ target + 10)
D. (target - 10 ≤ score) AND (score ≤ target + 10)
What is (D): (target - 10 ≤ score) AND (score ≤ target + 10)