Create PT - Function and List Requirement Activity
Create PT - Function and List Requirement Activity
This activity should help you better understand how to design the function you will submit. Remember that your function
needs to include "at least one procedure that uses one or more parameters to accomplish the program’s intended
purpose, and that implements an algorithm that includes sequencing, selection, and iteration." Make sure your program
includes a function that has a parameter, an if-statement, and a loop.
Be the AP Reader! You are the AP reader trying to determine if the responses below meet the program requirements for
a function. Assume each function below was submitted. For each, select whether it meets the requirements and why.
Be the AP Reader! You are the AP reader trying to determine if the responses below meet the program requirements for
a function. Assume each function below was submitted. For each, select whether it meets the requirements and why.
List Function
function checkWinner(board) {
if (board[0] === board[1]) {
List: if (board[1] === board[2]) {
A list representing the game board: if (board[0] !== "") {
["X", "O", "X", "", "", "O", "", "", "X"] return board[0];
}
}
}
if (board[3] === board[4]) {
if (board[4] === board[5]) {
if (board[3] !== "") {
return board[3];
}
}
}
if (board[0] === board[4]) {
if (board[4] === board[8]) {
if (board[0] !== "") {
return board[0];
}
}
}
return "No winner";
}
def checkCalories(calorieList):
for calories in calorieList:
List: if calories > 2000:
A list of calories consumed each day: print("You ate too many calories today.")
[2000, 2500, 1800, 2200] else:
print("You stayed within your calorie limit.")
List Function
function countShots(events) {
List: var shotCount = 0;
A list of events during a game: for (var i = 0; i < events.length; i++) {
["shot", "rebound", "shot", "foul"] if (events[i] === "shot") {
shotCount = shotCount + 1;
}
}
return shotCount;
})