AP Computer Science Principles
Programming (Khan Academy) UPDATED
ACTUAL Questions and CORRECT
Answers
Which of the following is a benefit of procedures for programmers? - CORRECT
ANSWER✔✔- Programmers can more easily understand programs with procedures, since
procedures give names to complex pieces of code.
Aarush is writing a program to help him calculate how much exercise he does at the gym.
The procedure calcSwimYards returns the number of yards swum for a given number of laps
in a pool of a given length.
PROCEDURE calcSwimYards(poolLength, numLaps)
{
lapLength ← poolLength * 2
RETURN lapLength * numLaps
}
Aarush then runs this line of code:
yardsSwum ← calcSwimYards(25, 10)
What value is stored in yardsSwum? - CORRECT ANSWER✔✔- 500
At that distance, the code should give the player a 30% chance of making the goal. -
CORRECT ANSWER✔✔- RANDOM(1, 100) <= 30
RANDOM(1, 10) <= 3
discount ← 0
IF (quantity <?> 150)
{
discount ← 10
,} ELSE
{
IF (quantity <?> 75)
{
discount ← 7
}
ELSE {
IF (quantity <?> 10)
{
discount ← 5
}
}
}
Which operator could replace <?> so that the code snippet works as expected? - CORRECT
ANSWER✔✔- ≥
IF (ironLevel < 10)
{
diagnosis ← "anemic"
}
ELSE
{
diagnosis ← "normal"
}
Which of these tables shows the expected values of diagnosis for the given values of
ironLevel?
Choose 1 answer: - CORRECT ANSWER✔✔- 4.5 "anemic"
8.2 "anemic"
9.9 "anemic"
10.0 "normal"
22.5 "normal"
,NOT ( calendar = "user" AND rsvp = "yes" ) - CORRECT ANSWER✔✔- calendar ≠ "user"
OR rsvp ≠ "yes"
This graph contains a line with unknown slope, going through the points [2, 1][2,1]open
bracket, 2, comma, 1, close bracket and [4, 3][4,3]open bracket, 4, comma, 3, close bracket: -
CORRECT ANSWER✔✔- (2, 1, 4, 3)
Program 1:
totalCalories ← 0
loggedMeals ← [700, 800, 600, 300]
FOR EACH loggedMeal IN loggedMeals
{
totalCalories ← totalCalories + loggedMeal
}
IF (totalCalories > 2000) {
excessCalories ← totalCalories - 2000
DISPLAY(excessCalories)
}
Program 2:
totalCalories ← 0
loggedMeals ← [700, 800, 600, 300]
FOR EACH loggedMeal IN loggedMeals
{
totalCalories ← totalCalories + loggedMeal
IF (totalCalories > 2000) {
excessCalories ← totalCalories - 2000
}
}
DISPLAY(excessCalories) - CORRECT ANSWER✔✔- Program 1 and Program 2 display
the same output, but Program 2 requires more computations.
, REPEAT UNTIL ( canTakeCheese() )
{
<MISSING CODE>
}
There are many ways for him to reach the cheese. Of the options below, which will require
the most repetitions of the loop? - CORRECT ANSWER✔✔- IF (facingWall())
{
turnRight()
}
ELSE
{
walkForward(2)
}
sentence ← ""
word1 ← "Hello"
firstLetter1 ← SUBSTRING(word1, 1, 1)
otherLetters1 ← SUBSTRING(word1, 2, LENGTH(word1) - 1)
pigLatin1 ← CONCAT(otherLetters1, firstLetter1, "ay")
sentence ← CONCAT(sentence, pigLatin1, " ")
word2 ← "Mister"
firstLetter2 ← SUBSTRING(word2, 1, 1)
otherLetters2 ← SUBSTRING(word2, 2, LENGTH(word2) - 1)
pigLatin2 ← CONCAT(otherLetters2, firstLetter2, "ay")
sentence ← CONCAT(sentence, pigLatin2, " ")
word3 ← "Rogers"
firstLetter3 ← SUBSTRING(word3, 1, 1)
otherLetters3 ← SUBSTRING(word3, 2, LENGTH(word3) - 1)
pigLatin3 ← CONCAT(otherLetters3, firstLetter3, "ay")
sentence ← CONCAT(sentence, pigLatin3, " ")