AP® Computer Science Principles 2025 Written Response Prompts: Detailed Solutions
A Note from Your AP CSP Educator: Welcome, future innovators! The AP CSP written response prompts are unique because they ask you to analyze and reflect on the program you created for the Create Performance Task. This means there is no single "correct" answer. Instead, your goal is to demonstrate a deep understanding of the computational concepts in your own code. This guide will provide a framework and model answers for a hypothetical project to show you *how* to approach these questions effectively. Remember to replace the specifics of the model project with the specifics of your own.
Sample Project: "Travel Planner"
To provide concrete answers, let's imagine a student submitted a "Travel Planner" app. Here are its key features:
- Purpose: Helps users plan a trip by suggesting activities based on their interests and budget.
- List: A list named
recommendedActivities
stores potential activities suggested by the program. Each element in the list is an object with properties like `name`, `category` (e.g., "Museum", "Outdoor", "Food"), and `cost`. - Procedure: A procedure named
findActivities(interest, maxCost)
takes a user's `interest` (a string like "Museum") and `maxCost` (a number) as parameters. It iterates through a master list of all possible activities and adds matching activities to therecommendedActivities
list. - Selection Statement (in the procedure):
IF (activity.category == interest AND activity.cost <= maxCost)
- List Traversal (in the procedure): A `FOR EACH activity IN allActivitiesList` loop.
Your Personalized Project Reference would contain code segments reflecting these features. We will use this hypothetical project to answer the prompts.
Prompt 1: Program Output and Functionality
Deconstructing the Prompt & Planning
Task: I need to do two things:
- Identify an example output: This means describing what the user sees on the screen as a result of running the program. It should be specific.
- Explain how the output shows functionality: I need to connect this specific output back to the program's purpose. How does what I see demonstrate that the program is doing what it's supposed to do?
Planning for the "Travel Planner" App:
- Identify an input: A user inputs "Food" as their interest and "20" as their max budget.
- Identify the corresponding output: The program displays a list on the screen: "Recommended for you: [Taco Stand, Noodle House]".
- Explain the functionality: This output shows the program's core functionality, which is to filter a larger list of activities based on user input for category and cost. The program successfully processed the inputs ("Food", 20) and searched its data to find only the activities that matched both criteria, demonstrating its purpose of providing personalized travel suggestions.
Model Response
Example Output: An example output of my program occurs after the user enters "Museum" for their interest and "25" for their maximum budget. The program then displays the text: "Here are your recommended activities: [Art Institute, Field Museum]".
Explanation of Functionality: This output demonstrates my program's core functionality, which is to provide users with a personalized list of travel activities based on their specified interests and budget. The program successfully took the user's input ("Museum", 25) and algorithmically processed a larger list of available activities. It correctly filtered this list to include only those activities whose category was "Museum" and whose cost was less than or equal to 25. By displaying only the "Art Institute" and the "Field Museum," the program shows it has successfully implemented this filtering logic to meet its stated purpose of helping users plan a trip.
Prompts 2A, 2B, and 2C
2A: Selection Statement Analysis
Task: Three parts: 1) Identify the Boolean expression. 2) Identify values that make it true. 3) Explain *why* those values make it true.
Planning for the "Travel Planner" App:
- Boolean Expression: The expression is
(activity.category == interest AND activity.cost <= maxCost)
. This is what's inside the IF statement. - Values for `true`: I need values for the variables in the expression. The variables are `interest`, `maxCost`, and the properties of the `activity` object being checked. Let's say the current `activity` being checked has `category = "Museum"` and `cost = 15`. The user-input parameters are `interest = "Museum"` and `maxCost = 25`.
- Explanation: I'll break down the expression. The left side,
activity.category == interest
, becomes"Museum" == "Museum"
, which is `true`. The right side,activity.cost <= maxCost
, becomes15 <= 25
, which is also `true`. Since both sides of the `AND` operator are `true`, the entire Boolean expression evaluates to `true`.
The Boolean expression in my selection statement is (activity.category == interest AND activity.cost <= maxCost)
.
A specific set of values that will cause this expression to evaluate to `true` is when the parameter interest
has the value "Museum", the parameter maxCost
has the value 30, and the current `activity` object being evaluated has a `category` property of "Museum" and a `cost` property of 20.
These values cause the expression to be `true` because both conditions of the `AND` operator are met. The first part, activity.category == interest
, becomes "Museum" == "Museum"
, which evaluates to `true`. The second part, activity.cost <= maxCost
, becomes 20 <= 30
, which also evaluates to `true`. Because the expression is true AND true
, the entire Boolean expression evaluates to `true`.
2B: Logic Error Modification
Task: Two parts: 1) Describe a modification that would cause a logic error. 2) Describe how the behavior would change.
Planning for the "Travel Planner" App:
- Identify the code to modify: The procedure
findActivities
contains the selection statementIF (activity.category == interest AND activity.cost <= maxCost)
. A logic error means the code runs but produces an incorrect or unexpected result. A simple way to introduce one is to change the logical operator. - Describe a modification: A programmer could mistakenly change the `AND` operator to an `OR` operator. The new code would be
IF (activity.category == interest OR activity.cost <= maxCost)
. - Describe the change in behavior: The original procedure was supposed to find activities that met *both* criteria. With the `OR`, the procedure will now add any activity that meets *either* criteria. For example, if the user inputs "Museum" and a budget of 20, the new list would incorrectly include an expensive museum that costs 50 (because the category matches) and also a cheap restaurant that costs 10 (because the cost matches). The program's behavior changes from providing a highly relevant, filtered list to providing a much larger, less relevant list that includes items the user is not interested in or cannot afford.
Modification with Logic Error: Within my findActivities
procedure, another programmer could introduce a logic error by changing the AND
operator in the selection statement to an OR
operator. The modified line of code would read: IF (activity.category == interest OR activity.cost <= maxCost)
.
Change in Behavior: This modification would cause the procedure's behavior to become incorrect. The original procedure was designed to recommend only activities that matched *both* the user's interest and budget. With the OR
operator, the procedure will now add an activity to the list if it matches *either* the interest or the budget. For a user who requests "Outdoor" activities with a maximum cost of 15, the program would now incorrectly recommend an expensive "Outdoor" hike that costs 50, as well as an affordable but irrelevant "Museum" that costs 10. The result is a less useful and incorrect list of recommendations that no longer meets the program's intended purpose.
2C: List Modification
Task: Explain how the code that traverses the list would need to be modified if new elements are added to the list. If no change is needed, explain why.
Planning for the "Travel Planner" App:
- Recall the list and traversal: The list is `allActivitiesList`. The code that traverses it is a `FOR EACH` loop:
FOR EACH activity IN allActivitiesList
. - Consider the effect of adding elements: If new activities are added to the end of `allActivitiesList`, how does the `FOR EACH` loop handle it?
- Analyze the loop type: A `FOR EACH` loop (or an enhanced for loop in many languages) is designed to iterate over every single element in a collection, regardless of its size. It doesn't rely on a hard-coded number of iterations or an index limit. It simply continues until it has processed every element.
- Conclusion: Therefore, no changes are necessary.
- Formulate the explanation: I need to explain *why* no changes are needed, focusing on the properties of the `FOR EACH` loop. It automatically adapts to the length of the list.
If another programmer adds new elements to the end of the list, no changes to the code segment in part (ii) of the List section would be necessary.
This is because my program uses a FOR EACH
loop to traverse the list of activities. This type of loop is designed to iterate over every element in a collection, starting from the first element and continuing until the last element has been processed. The loop's execution is not dependent on a hard-coded index number or the original length of the list. Therefore, if new activities are added, the FOR EACH
loop will automatically include them in its traversal, checking each new activity against the user's criteria without any need for modification to the loop structure itself.
AP® Computer Science Principles 2025 Written Response Prompts (Set 2): Detailed Solutions
A Note from Your AP CSP Educator: Hello, programmers! These AP CSP written response prompts require you to analyze and explain the code you wrote for your own Create Performance Task. This means the 'correct' answer is specific to your project. To help you master the *skills* needed to answer, this guide will use a hypothetical project to demonstrate how to approach each prompt. You should apply these same thinking processes to your own unique program and code segments from your Personalized Project Reference.
Sample Project: "Study Buddy Quiz"
For these model answers, let's assume a student created a "Study Buddy Quiz" app.
- Purpose: To help users study for a test by quizzing them with multiple-choice questions. The program tracks the user's score.
- Input: The user inputs their answer for each question (e.g., "A", "B", "C", or "D").
- List: A list named
questionBank
stores the quiz questions. Each element in the list is an object with properties like `prompt`, `options`, and `correctAnswer`. - Procedure: A procedure named
checkAnswer(userAnswer, questionIndex)
takes the user's input and the index of the current question. It compares the user's answer to the correct answer stored in the list. - Selection Statement (in the procedure):
IF (userAnswer == questionBank[questionIndex].correctAnswer)
- List Traversal (for displaying the final score): A `FOR EACH` loop named
calculateFinalScore()
iterates through a list of boolean values (resultsList
, where `true` means a correct answer) to count the number of correct responses.
Your Personalized Project Reference would contain code segments reflecting these features. We will use this hypothetical project to answer the prompts.
Prompt 1: Unexpected or Invalid Input
Deconstructing the Prompt & Planning
Task: Three parts:
- Identify an unexpected or invalid input: Think about what the user is supposed to enter versus what they *could* enter.
- Describe the program's behavior: What happens on screen when this invalid input is received? Does it crash? Does it show an error message? Does it just ignore it?
- If not possible, explain why: If my program is designed to prevent invalid input (e.g., using a dropdown menu), I need to explain that design choice.
Planning for the "Study Buddy Quiz" App:
- Identify invalid input: The program expects the user to type "A", "B", "C", or "D". An invalid input would be any other character, like "E", or a number like "5", or a word like "cat".
- Describe the behavior: Let's assume my program has some basic error handling. When the user enters "E", the program doesn't crash. Instead, it compares "E" to the correct answer (e.g., "A"). Since they don't match, it treats it as an incorrect answer. It might display a message like "Incorrect. The correct answer was A." and then move to the next question without adding to the score.
- Alternative (if input is constrained): If I had designed the quiz with buttons for "A", "B", "C", and "D" instead of a text box, it would be impossible for the user to provide an input like "E". I would then explain that the user interface design, by only providing valid options to click, prevents invalid input from ever being accepted by the program.
Model Response
Unexpected or Invalid Input: An unexpected or invalid input a user could provide to my quiz program is typing the letter "E" into the answer field, when the program only expects one of the valid multiple-choice options "A", "B", "C", or "D".
Program Behavior: After my program receives the invalid input "E", it proceeds without crashing. The checkAnswer
procedure compares the user's input, "E", to the correct answer stored for that question (for example, "C"). Because "E" does not equal "C", the program's selection statement evaluates to false. It then executes the code for an incorrect answer, which displays the message "Sorry, that is not correct" and moves on to the next question without incrementing the user's score. The program effectively treats any invalid input as simply a wrong answer.
Prompts 2A, 2B, and 2C
2A: Selection Statement Analysis (evaluating to false)
Task: Three parts: 1) Identify the Boolean expression. 2) Identify values that make it `false`. 3) Explain *why* those values make it `false`.
Planning for the "Study Buddy Quiz" App:
- Boolean Expression: The expression is
(userAnswer == questionBank[questionIndex].correctAnswer)
. - Values for `false`: This is simple. The user's answer just needs to not match the correct answer. Let's say the current question's correct answer is "A". So,
questionBank[questionIndex].correctAnswer
has the value "A". The user inputs "B", souserAnswer
has the value "B". - Explanation: The comparison operator
==
checks for equality. The expression becomes"B" == "A"
. Since the string "B" is not equal to the string "A", the expression evaluates to `false`.
The Boolean expression in my selection statement is userAnswer == questionBank[questionIndex].correctAnswer
.
A specific set of values that will cause this expression to evaluate to false
is when the userAnswer
variable holds the string "B", and the `correctAnswer` property of the question object at questionBank[questionIndex]
holds the string "A".
This set of values causes the expression to evaluate to false
because the equality operator ==
compares the two values. The statement "B" == "A"
is evaluated, and since the string "B" is not the same as the string "A", the comparison results in a `false` value.
2B: List Traversal Logic Error
Task: Two parts: 1) Describe a modification to the list traversal code segment that causes a logic error. 2) Explain why it's a logic error.
Planning for the "Study Buddy Quiz" App:
- Identify the code segment: The list traversal is in the
calculateFinalScore()
loop, which iterates throughresultsList
. Let's imagine the code looks like this:score = 0
FOR EACH result IN resultsList {
IF (result == true) {
score = score + 1
}
} - Describe a modification: A common logic error in loops is an "off-by-one" error or incorrect initialization. A programmer could mistakenly initialize the score incorrectly. For example, they could change
score = 0
toscore = 1
before the loop begins. - Explain the logic error: This is a logic error because the code will still run without crashing, but it will produce an incorrect final score. The score should start at 0 before any correct answers are counted. By starting the score at 1, the final calculated score will always be one point higher than the user actually earned. For a user who gets 7 out of 10 questions correct, the program would incorrectly report their score as 8.
Modification with Logic Error: My code segment for calculating the final score initializes a variable, score
, to 0 before the loop begins. A programmer could introduce a logic error by modifying this initialization to score = 1
.
Explanation of Logic Error: This modification would result in a logic error because the program would consistently report a final score that is one point higher than the user actually achieved. The purpose of the score
variable is to act as an accumulator that starts at zero and is incremented only for each correct answer. By incorrectly initializing it to 1, the program gives the user a "free" point before the loop even begins to count their correct answers. The code would execute without crashing, but the final output would be fundamentally incorrect, which is the definition of a logic error.
2C: Procedure Abstraction
Task: Three parts: 1) Describe the functionality of the procedure. 2) Explain how using a procedure makes the program easier to maintain. 3) Contrast this with not using a procedure.
Planning for the "Study Buddy Quiz" App:
- Describe functionality: The procedure is
checkAnswer(userAnswer, questionIndex)
. Its functionality is to determine if a user's submitted answer for a specific question is correct. It takes the user's answer and the question's index as input, compares the input to the correct answer stored in thequestionBank
list, and then updates the user's score and provides feedback accordingly. - Explain benefit of procedure (maintenance): Procedures (abstractions) make programs easier to maintain because they encapsulate a specific piece of functionality. If I need to change how an answer is checked (e.g., make it case-insensitive, or award partial credit), I only have to modify the code inside the
checkAnswer
procedure. All the parts of my program that call this procedure will automatically use the updated logic without needing to be changed themselves. - Contrast with no procedure: If I had *not* used a procedure, I would have had to copy and paste the answer-checking code for every single question in my quiz. If my quiz had 10 questions, that's 10 blocks of nearly identical code. If I then decided to change the scoring logic, I would have to find and modify all 10 of those blocks individually. This would be time-consuming, tedious, and highly prone to errors (e.g., forgetting to update one of the blocks), making the program much harder to maintain and debug.
Functionality of Procedure: The functionality of my checkAnswer
procedure is to evaluate if the answer provided by the user for a given question is correct. It accepts the user's submitted answer and the index of the current question as parameters. It then retrieves the correct answer from my questionBank
list using the index and compares it to the user's answer, updating the score and displaying appropriate feedback.
Explanation of Easier Maintenance: Implementing this functionality as a procedure makes the program much easier to maintain by managing complexity through abstraction. The logic for checking an answer is contained in one single location. If I later decide to change this logic—for example, to make the answer check case-insensitive or to add a feature for partial credit—I only need to modify the code within the checkAnswer
procedure once. Every part of my program that calls this procedure will automatically benefit from the update.
If this functionality were not implemented as a procedure, the code for checking an answer would have to be repeated for every question in the quiz. To make a single change to the checking logic, I would have to locate and edit every single instance of this repeated code. This would not only be inefficient but would also dramatically increase the risk of introducing errors by accidentally missing an instance or making an inconsistent change, thus making the program significantly more difficult to manage and maintain.