Students will gain experience writing code in the agnostic language of AP CSP.
AAP-2.K.2: The exam reference sheet provides
REPEAT n TIMES
{
<block of statements>
}
in which the block of statements is executed n times.
AAP-2.K.3: The exam reference sheet provides
REPEAT UNTIL(condition)
{
<block of statements>
}
in which the code in block of statements is repeated until the Boolean expression condition evaluates to true.
AAP-2.K.4: In REPEAT UNTIL(condition) iteration, an infinite loop occurs when the ending condition will never evaluate to true.
AAP-2.K.5: In REPEAT UNTIL(condition) iteration, if the conditional evaluates to true initially, the loop body is not executed at all, due to the condition being checked before the loop.
AAP-2.L: Compare multiple algorithms to determine if they yield the same side effect or result.
AAP-2.L.1: Algorithms can be written in different ways and still accomplish the same tasks.
AAP-2.L.2: Algorithms that appear similar can yield different side effects or results.
AAP-2.L.3: Some conditional statements can be written as equivalent Boolean expressions.
AAP-2.L.4: Some Boolean expressions can be written as equivalent conditional statements.
AAP-2.L.5: Different algorithms can be developed or used to solve the same problem.
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 sprint of their ARC Challenge.
Activity 5.5.1 (30 minutes)
This activity should be handwritten. Students will not be using a program to code.
Students should be provided with a copy of the AP CSP exam reference sheet.
Students should follow the prompt asking to write a script that does the following:
define a variable named songs with a blank string "" assigned to it
define a variable named numSongs that is initialized to 0
write code utilizing a REPEAT block that produces the following string assigned to the variable songs:
"song1 and song2 and song3 and song4 and song5"
this REPEAT block should also keep track of the total number of songs by adding to the numSongs variable
for each iteration of the REPEAT block, print out how many songs are currently added to the string
prints out the length of songs
Teachers can use this answer key for this activity.