APCSP Exam
If the value of x is 3 and the value of y is 5, what is displayed as a result of executing the code segment?
-2
Which of the following initial values of the variable y would result in the variable z being set to 2 after the code segment is executed?
3
Enter the number that indicates how many syntax errors you can find in the following code segment:
4
Given the procedures given for substring and concat, what does the following code segment output for temp?
"M"
What is the value of myChar ?
"h"
Given the procedures for substring, concat, and len, what does the following code segment output for second?
"hant"
Given the procedures for substring, concat, and len, what does the following code segment output for first?
"tig"
Given the procedures for substring, concat, and len, what does the following code segment output for newAnimal?
"tighant"
Using the following code segment, what is the cost of purchasing 3 scoops of ice cream on a waffle cone with no toppings?
$4.5- maybe??
Using the following code segment, what is the cost of purchasing 3 scoops of ice cream on a regular cone with no toppings?
$4.5- maybe????
Which of the following expressions evaluates to true if the student is eligible to attend the camp and evaluates to false otherwise?
((age ≥ 13) OR (grade ≥ 9)) AND (age < 18)
Which of the following expressions evaluates to true if the person is old enough to drive but not old enough to vote, and evaluates to false otherwise? (Check all that apply)
(age ≥ 16) AND (age ≥ 18) (age < 18) AND (NOT(age < 16))
Which of the following is a Boolean expression that checks if the average of grade1, grade2, and grade3 is at least 70?
(grade1 + grade2 + grade3) / 3 ≥ 70
Let n be an integer value. Which of the following expressions evaluates to true if and only if n is a two-digit integer (i.e., in the range from 10 to 99, inclusive)?
(n ≥ 10) AND (n < 100)
Which of the following expressions evaluates to true if the student is eligible for the scholarship and evaluates to false otherwise?
(overallGPA ≥ 3.0) AND (scienceGPA > 3.2)
6 * 10 / 5 % 3 * 2
0
What is the value of sum after the code segment is executed?
16
What is the value of r as a result of executing the code segment?
20
What is displayed as a result of executing the code segment?
21 40 30 50
6 * 10 / 5 * 2
24
Given the procedures for substring, concat, and len, what does the following code segment output for len1?
3
If the value of score1 is 350 and the value of score2 is 210, what will be the value of result after the code segment is executed?
5
A "While loop header" ends with which of the follow?
:
Which of the following algorithms can be used to open the gate under the appropriate conditions?
Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is open. If it is not, turn on the motor.
Which of the following code segments will assign the correct letter grade to grade based on the value of the variable score ?
II and III only
A certain game keeps track of the maximum and minimum scores obtained so far. If num represents the most recent score obtained, which of the following algorithms correctly updates the values of the maximum and the minimum?
If num is less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.
Which of the following code segments correctly sets the value of the variable cost to the cost, in dollars, of using numUnits units of electricity?
If the number of units of electricity used is 25 or less, the cost is 5 times the number of units. Otherwise, the cost is 5 times the first 25 units plus 7 times the number of units above 25.
Block Strings
In Python, strings that begin with ''' and can span multiple lines. They are often used to temporarily deactivate code.
Select each of the following that is a true statement.
In the my_turtle.circle(5) statement, my_turtle is an object. A class design is like a blueprint or a recipe.
Which of the following changes can be made so that the code segment works as intended?
Interchanging lines 3 and 7
Which of the following best describes the behavior of the procedure?
It displays true if x is negative and displays nothing otherwise
What is the output resulting from the following code? x = "My favorite color is" y = "blue" print(x,y)
My favorite color is blue
Drag the following in the correct order of arithmetic operation
Parentheses Exponents Multiplication Division Addition Subtraction (PEMDAS)
Which of the following is the most appropriate documentation to appear with the printNums procedure?
Prints all positive odd integers that are less than or equal to max.
Which of the following is a mistake when a programmer makes a typo or writes code (or forgets to write some code) that doesn't follow the rules of the language?
Syntax error
What is displayed as a result of executing the code segment?
false,false,false
Picture question
go with it
Which of the following assigns the correct string to initials ?
initials ← concat(prefix(firstName, 1), prefix(lastName, 1))
The line wn.mainloop() is used to keep the turtle screen from exiting once the program is complete; therefore, the screen will persist, allowing the user to close the screen. The mainloop method must be the last statement in a turtle graphics program.
true
What is displayed after running the following code segment? name ← "Mitchell" age ← 34 DISPLAY (NOT (name = "Mitchell")) OR (age < 40)
true
What is displayed after running the following code segment? num ← 7 isEven ← num MOD 2 = 0 range ← (num > 5) AND (num ≤ 10) DISPLAY (isEven OR range)
true
truckWeight < weightLimit What value does the expression evaluate to?
true
If category is "new" and age is 20, what are the values of val1 and val2 as a result of executing the code segment?
val1 = false, val2 = false
Which of the following code segments can be used to store "noon" in the string variable word?
word ← "on" word ← concat(reverse(word), word)
Which of the following will assign the variable x an integer data type? (Select all that apply)
x = 50
Which of the following will assign the variable x a string data type?
x = input("What is your name?") x = "1000" x = input("What is your lucky number?")
Which of the variables have the value 50 after executing the code segment?
x and z only
Choose which of the following is a relational operator. (Check all that apply)
≥ ≠ < > = ≤
Given the procedures for substring, concat, and len, what does the following code segment output for len2?
4
The list wordList contains a list of 10 string vlaues. Which of the following is a valid index for the list?
4
For which of the following values of numCorrect does the code segment NOT display the intended grade?
6 9
Choose any of the statements below that is NOT TRUE regarding runtime errors.
A runtime error is often referred to as a "bug" in a program.
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 string variable named studentName and a Boolean variable named isAbsent
The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Boolean
A company that develops educational software wants to assemble a collaborative team of developers from a variety of professional and cultural backgrounds. Which of the following is NOT considered a benefit of assembling such a team?
Collaboration that includes diverse backgrounds and perspectives can eliminate the need for software testing.
Using nested conditional statements, which of the following pseudocode samples would correctly match the information in the table below?
DISPLAY ("Is the employee certified? true or false")isCertified ← INPUT ()DISPLAY ("How many years experience?")yearsExperience ← INPUT()salary ← 35000IF (isCertified){IF (yearsExperience < 10){salary ← salary + 10000}ELSE{salary ← salary + 15000}}
Which of the following is the most appropriate documentation to appear with the calculate procedure?
Displays the value of (x + y) / x The value of the parameter x must not be 0.
Forgetting to add a colon at the end of an "if" statement is an example of a logic error.
False
The begin_fill() in a Python Turtle program specifies the start of the shape that will use the fill color you've chosen to use; however, the fill color must be set after the begin_fill() method.
False
Given the procedures given for substring and concat, what does the following code segment output for email?
Three students in different locations are collaborating on the development of an application. Which of the following strategies is LEAST likely to facilitate collaboration among the students?
Having all three students write code independently and then having one student combine the code into a program.
Which of the following pseudocode examples matches with the following block pseudocode?
IF ((time < 3) AND (score > 1000){ lives ← lives + 3}ELSE{IF ((time < 3) OR (score > 1000)){lives ← lives + 1}ELSE{lives ← lives - 1} }
Which of the following data are needed for DineOutHelper to recommend a restaurant for the group?
II and III only
Which of the following data is not provided by Alejandra but is necessary for DineOutHelper to recommend a restaurant for the group?
II only
Which of the following is NOT TRUE regarding file compression that is stored in a format that makes the file size smaller to save space on the ?
It takes longer to download a compressed file to your digital device.
A programmer has a need to round many numeric values to the nearest integer. Which of the following best explains the benefit of using a list as a data abstraction in this situation?
Keeping the numeric values in a list makes it easier to apply the same computation to every data element.
Which of the following is a benefit of using a list as a data abstraction in a program?
Lists often allow their size to be easily updated to hold as many data values as needed.
Select each of the following that is TRUE regarding Object-Oriented Programming
Methods are the actions that your objects can take. Object-oriented programs remove details from many programs, making code rewrite less frequent.
Which of the following gives the same result as the following expression? (Check all that apply) age ≥ 16
NOT (age < 16) age > 16 OR age = 16
Which Boolean expression example should be used for the following scenario? You can leave your umbrella at home if it is not cloudy and the temperature is greater than 75.
NOT (isCloudy) AND temp > 75
Choose which of the following is a logical operator. (Check all that apply)
OR NOT AND
Which of the following happens when a computer attempts to handle a number that is outside of the defined range of values?
Overflow Error
Which of the following is the most appropriate documentation to appear with the swapListElements procedure?
Returns a copy of numList with the elements at indices j and k interchanged. The values of j and k must both be between 1 and LENGTH (numList), inclusive.
A teacher has a goal of displaying the names of 2 students selected at random from a group of 30 students in a classroom. Any possible pair of students should be equally likely to be selected. Which of the following algorithms can be used to accomplish the teacher's goal?
Step 1: Assign each student a unique integer from 1 to 30. Step 2: Generate a random integer n from 1 to 30. Step 3: Select the student who is currently assigned integer n and display the student's name. Step 4: The student who was selected in the previous step is assigned 0. All other students are reassigned a unique integer from 1 to 29.. Step 5: Generate a new random integer n from 1 to 29. Step 6: Select the student who is currently assigned integer n and display the student's name.
Which of the following algorithms displays the correct distance for all possible values of num1 and num2 ?
Step 1: Subtract num1 from num2 and store the result in the variable diff. Step 2: Take the absolute value of diff and display the result.
Consider the following code segment with integer variables x and y. If x has a value of 7 and y has a value of 20, what is displayed as a result of executing the code segment?
THREE
Which of the following best describes the behavior of the code segment?
The code segment displays the value of 2(53) by initializing result to 2 and then multiplying result by 5 a total of three times
The code segment compares pairs of list elements, setting containsDuplicates to true if any two elements are found to be equal in value. Which of the following best describes the behavior of how pairs of elements are compared?
The code segment iterates through myList, comparing each element to all subsequent elements in the list.
A student is creating an application that allows customers to order food for delivery from a local restaurant. Which of the following is LEAST likely to be an input provided by a customer using the application?
The cost of a food item currently available for order
What are the values of first and second as a result of executing the code segment?
The value of first is true, and the value of second is true.
Which of the following code segments assigns bonus correctly for all possible integer values of score ? Select two answers.
This code segment sets bonus to 0 when score < 50, sets bonus to score * 10 when score > 100, and sets bonus to score when 100 ≥ score ≥ 50. This code segment sets bonus to score * 10 when score > 100, sets bonus to score when 100 ≥ score ≥ 50, and sets bonus to 0 when score < 50.
Which of the following code segments correctly sets the value of maxPS based on the value of time ? Select two answers.
This code segment uses the IF statement to set maxPS to 30 when time > 120 and uses the ELSE statement to set maxPS to 50 otherwise. This code segment sets maxPS to 50 by default, then uses the IF statement to set maxPS to 30 when time > 120.
A company that develops mobile applications wants to involve users in the software development process. Which of the following best explains the benefit in having users participate?
Users can provide feedback that can be used to incorporate a variety of perspectives into the software.
Under which of the following conditions will the value "C" be assigned to the variable grade ?
When the value of exam is 80 and the value of presentation is 60
What are the contents of secondList after the code segment is executed?
["guitar" , "drums" , "bass"]
For which of the following contents of myList does the procedure NOT return the intended result?
[-1, 0, 1]
What are the contents of yourList after the code segment is executed?
[10, 30, 50, 70]
In most states, the minimum age to drive is 16. How would you write a Boolean expression to check if someone is at least 16 years old?
age ≥ 16
Programming constructs such as a == b are called _________________ and are usually used in a while or if statement.
conditional expressions
Which Boolean expression example should be used for the following scenario? You can go out if you did your homework and you scored at least an 80 on your computer science exam.
didHomework AND score ≥ 80
The line of code, wn = trtl.Screen(), saves a turtle screen object called Screen, giving the program a way to control screen-level behavior, such as when to close the turtle screen.
false
A _________ error is caused by the programmer making a mistake in the algorithm, which causes the program to behave unexpectedly.
logic
A predefined set of instructions that can be used to accomplish a task is called a(n) ___________. In Python, some examples for the turtle are forward(), backward(), circle(), penup(), and pendown().
method
Which of the following code segments can be used to assign the intended string to newString ? Select two answers.
newString ← substring(oldString, 3, len(oldString) - 4) tempString ← substring(oldString, 3, len(oldString) - 2) newString ← substring(tempString, 1, len(tempString) - 2
Which of the following is a Boolean expression that determines whether or not num1 is odd?
num1 MOD 2 = 1
The variable age is to be used to represent a person's age, in years. Which of the following is the most appropriate data type for age ?
number
What is the correct syntax to output "Hello World" in Python?
print("Hello World")
A class design is used to create an instance of a class, called an object.
true
An "if / else" statement can be used to evaluate 2 different outcomes based off of a condition being true or false.
true
In Python, you calculate the remainder of division with the modulo operator % .
true