Section 7.9
Coding Task
Learning Goals
Students will gain experience writing code in the agnostic language of AP CSP
AAP-2.H.2: The exam reference sheet provides
IF(condition)
{
<block of statements>
}
in which the code in block of statements is executed if the Boolean expression condition evaluates to true; no action is taken if condition evaluates to false.
AAP-2.H.3: The exam reference sheet provides
IF(condition)
{
<first block of statements>
}
ELSE
{
<second block of statements>
}
in which the code in first block of statements is executed if the Boolean expression condition evaluates to true; otherwise, the code in second block of statements is executed.
Objectives and Description
The objective of this lesson is to provide students with exposure to the agnostic coding language used in the AP CSP exam through a coding task. Additionally, this task is meant to prepare students for the second sprint of their ARC Challenge.
Activities
Activity 7.9.1 (55 minutes)
Students should be provided with a copy of the AP CSP exam reference sheet
Students should write a script that follows the prompt below:
create an empty string assigned to a variable named songStructure
define a procedure named writeSong that takes the number of choruses (which will always be at least 2) as an argument
each section of the song added to songStructure should be separated by " -> "
add verses to songStructure until the correct number of choruses have been added
add a chorus after every 2 verses
if there is one chorus remaining, add a bridge instead of the 2 verses
after the correct number of choruses have been added, add an outro
print out the final song structure
For example, the final song structure for a song that has 3 choruses should be the following:
"verse -> verse -> chorus -> verse -> verse -> chorus -> bridge -> chorus -> outro"
The answer key for this prompt is provided for the teachers.