0% found this document useful (0 votes)
10 views4 pages

Create PT - Function and List Requirement Activity

The document outlines requirements for designing functions in JavaScript and Python, emphasizing the need for parameters, loops, and selection statements. It provides examples of functions that either meet or do not meet these criteria, along with explanations for each case. Additionally, it presents project ideas for a Tic-Tac-Toe game, a health app, and a sports stats app, including suggested data structures and processing functions.

Uploaded by

sod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Create PT - Function and List Requirement Activity

The document outlines requirements for designing functions in JavaScript and Python, emphasizing the need for parameters, loops, and selection statements. It provides examples of functions that either meet or do not meet these criteria, along with explanations for each case. Additionally, it presents project ideas for a Tic-Tac-Toe game, a health app, and a sports stats app, including suggested data structures and processing functions.

Uploaded by

sod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Function Requirement Activity - (JavaScript)

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.

Example Algorithm 1 Meet requirements? Yes / No

function repeatWord(word, times){ Why?


var returnWord = "";
for(var i = 0; i < times; i++){ This function meets the requirements because:
returnWord = returnWord + word;  Parameter: word, times
}  Loop: for loop iterates times times.
return returnWord;  Sequencing: Concatenates word to returnWord in
} each iteration.
 Selection: Not explicitly needed in this case but
still valid since it meets all other requirements.

Example Algorithm 2 Meet requirements? Yes / No

function increaseScore(points){ Why?

score = score + 1;  The function includes a parameter and an if


if(score > 10){ statement (selection).
endGame();  Missing: The function does not include iteration,
} such as a loop, so it does not fully meet the
} requirements.

Example Algorithm 3 Meet requirements? Yes / No

function addList(list){ Why?


var total = 0;
for(var i = 0; i < list.length; i++){ This function meets the requirements because:
total = total + list[i];  Parameter: list
}  Loop: for loop iterates through the list.
return total;  Sequencing: Adds each item to total.
}  Selection: Not explicitly present, but the problem
does not require all elements in every function.

Example Algorithm 4 Meet requirements? Yes / No


function addPositives(list){
var total = 0; Why?
var currentItem;
for(var i = 0; i < list.length; i++){ This function meets the requirements because:
currentItem = list[i];  Parameter: list
if(currentItem > 0){  Loop: for loop iterates through the list.
total = total + list[i];  Selection: if statement checks for positive values.
}  Sequencing: Adds positive values to total.
}
return total;
}
Function Requirement Activity - (Python)
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.

Example Procedure 1 Meet requirements? Yes / No

def repeatWord(word, times): Why?


returnWord = ""
for count in range(0, times):  Parameter: word, times
returnWord = returnWord + word  Loop: for loop iterates times times.
return returnWord  Sequencing: Concatenates word to returnWord in
each iteration.
 Selection: Not explicitly required for this function
to meet requirements.

Example Procedure 2 Meet requirements? Yes / No

def increaseScore(points): Why?


score = score + 1
if(score > 10):  Missing: The function does not include a loop or
endGame() iteration.

Example Procedure 3 Meet requirements? Yes / No

def addList(list): Why?


total = 0
for index in range(len(list)):  Parameter: list
total = total + list[index]  Loop: for loop iterates through the list.
return total  Sequencing: Adds each item to total.
 Selection: Not explicitly included but
unnecessary here.

Example Procedure 4 Meet requirements? Yes / No

def addPositives(list): Why?


total = 0
for index in range(len(list)):  Parameter: list
currentItem = list[index]  Loop: for loop iterates through the list.
if currentItem > 0:  Selection: if statement checks for positive values.
total = total + list[index]  Sequencing: Adds positive values to total.
return total

List and Function


Below are three descriptions of potential projects that another CS Principles student is considering.
For each write an idea for a list that would store data and a function that would process the data in the list.
Project 1: Tic-Tac-Toe
“Here’s my idea: I want to build a tic-tac-toe game. The user creates an account if they don’t already have one and are
taken to the main game board. From there the player will play against the computer in either easy, intermediate, or
advanced mode, so I will need to write the code for the computer player. When the game is over their lifetime win total is
updated. I will also keep track of how long the game took.”

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";
}

Project 2: Health App


“I volunteer at my local health clinic, so I want to build a health app. The user can record information about what they eat,
how much they sleep, how much they exercise, and information like their blood pressure and weight. Based on the
information provided the app will provide recommendations to the user about how they can improve their health for both
diet and exercise. Users can also personalize the look of the app with different theme colors.”
List Function

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.")

Project 3: Sports Stats


“I think that I’ll build an app that allows the user to quickly record stats during a basketball game. The app will show a
picture of the court. The user taps on the court to indicate something happened there. They are presented with a quick
menu of options like: shot attempt, foul, steal, rebound, etc. then they select from another list which player did it. At the
end of the game it displays a stat sheet for all of the players and the stats for that game.”

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;
})

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy