Draft Unit 2 Lab 2 Using Variables and Data Structures to Make Art Page 4 Key
ST EK List:
5.2.1E Program execution automates processes.
5.5.1H Computational methods may use lists and collections to solve problems.
Processing Each Item in a List
Ruthless Suggestions from Al
- The [lab] title: "Using Variables and Data Structures to Brand Art"—Information Structures are all over this, only I see no use of "variable." Radical suggestion: Maybe this won't piece of work, but can we save "variable" for things that get assigned and use "input" for things that get passed in when a command or reporter is called?
- The championship has already been inverse, merely I kept the comment considering of the question. Thoughts, Brian? --MF, v/16/18
- Radical suggestion: Do we need to declare information types? It's only one more thing for the user to runway.
- No, but we do it in our blocks, so we thought we should testify how information technology's washed. I think it should be in a yellow box. Brian, why did yous opt for light-green? --MF, five/16/xviii
- # 1: What does it mean: "Load and build their go to betoken block." And when I load it, I meet a listing.
- I think this but needs some clarification. --MF, v/16/18
This project has for each already imported. The folio should be clear that students volition have to import tools if they want to use for each in their own projects. --MF, eleven/15/17
In this lab, you will create tools for drawing complex designs from lists of points. To do this, y'all will use problem decomposition—breaking downwardly the problem into smaller pieces.
On this page, you lot volition create a script that lets yous connect the dots (given by a list of points) to draw the letter A.
Alphie and Betsy are edifice a programme that will take a list of points (each of which is a list of x and y coordinates) equally input and connect the dots. They figure they can apply information technology to depict pictures or graphs of data:
To make a gear up of starting data, they sketched the letter A on graph paper. They chose a scale that they figured would make their picture a good size on the stage.
ST-Many NYC teachers were confused and idea they are creating the list A themselves whereas we requite it to them in the starter file.
Then they listed the coordinates of each vertex, starting at the pointer and going clockwise effectually the figure. The first point is at (-l, xx), the 2d is (-ten, 120), and and then on. Then they built that listing in Snap! like this:
Now they need a script that will employ that list to make the drawing, like this:
Betsy: This listing of coordinates outlines an A, and so let's name it A.
Betsy clicks Make a variable, names it A, and builds
.
Then she clicks that gear up block to run it.
Alphie: So, for each of those eight points, we want the sprite to motion to it. Hmmm...
won't work, because information technology needs 2 separate inputs. Nosotros need a block that takes ane input, a point like
.
Betsy: And then nosotros'll brand a new block. Let's call it get to point. Information technology'll work like this
. We'll use
or
within it, but we'll take to process the input,
, to supply x: and y: separately. Hmmm...
Gamal: Oh! I know how! I bet nosotros tin can utilize
. Give information technology a number every bit its first input. I bet that the
just says that it expects a list every bit its second input.
Alphie: I wonder if nosotros can brand our go to point cake show that information technology expects a list as input....
Yes, you can make your blocks testify what blazon of data they expect as inputs: a number, a listing, or some other blazon. Some languages require the information type to be indicated. In Snap! information technology's an choice. It'due south not necessary but, similar assigning a colour to a block, information technology tin exist a helpful reminder of what the cake does and what type of input it expects. You've already seen input slots of several shapes, indicating different expected data types.
Notice in the video that there are many input types you can specify (Text, Number, Boolean, etc.) The list input type is chosen considering a indicate is a list of 2 coordinates.
-
It contains the listing of points, but you lot need to build their
block. - Click on the arrow to the right of the input name:
- Choose the information type y'all want for that input.
- Click OK.
- Finish edifice your
get to pointcake and test your block with a few points as input to make sure it does what y'all want information technology to.
Specifying an Input Type
This animation shows yous how to specify the list input type. Other input types are specified the same way.
After creating the championship and naming the input,
Alphie: Groovy! At present nosotros tin can use our go to point block for each of the points in our list.
Betsy: I bet we can use
.
Alphie and Betsy design this new script to automate the process of going to each signal.
And so they test it out.
Alphie: Yup! for each does exactly what nosotros desire. Simply we have a couple of bugs to fix.
- Build and examination the script they used.
- Prepare the two bugs Alphie noticed.
-
"U2L2-DrawShape"
- Think and write:
- For what purposes might y'all not want to connect the beginning and concluding points?
- For what purposes might y'all want to accept the pen down merely when the sprite marks each bespeak, simply never when the sprite moves from ane point to some other?
- For what purposes might you lot prefer
go tooverglide?
- Create three new points and a script that draws the complete letter A. Y'all'll have to pattern a way to indicate in a listing of points that they aren't all connected.
Choose the additional coordinates yourself.
Self-Check: For Each
- These questions are similar to those you will encounter on the AP CSP exam.
inputList ← [3, -1, ii, 10, -5] FOR EACH item IN inputList { IF ( (item > 0) AND (detail * item > 4) ) { DISPLAY detail } }What volition be displayed every bit a issue of running the lawmaking segment given?
9, 1, 4, 100, 25
These are non items from the inputList. What does the conditional in the procedure do?
ix, 100
These are not items from the inputList. What does the conditional in the procedure do?
Procedure Mystery (numberList, targetNumber) { counter ← 0 FOR EACH number IN numberList { IF (number > targetNumber) { counter ← counter + one } } Return (counter) } myMathGrades ← [100, 80, ninety, 80, 60, 100, l, 100] Mystery(myMathGrades, lx)What will be returned if the code to a higher place is run?
[100, eighty, 90, 80, 100, 100]
What kind of value does the procedure render?
60
What is the procedure doing?
Source: https://bjc.edc.org/March2019/bjc-r/cur/programming/2-complexity/2-data-structures-art/1-the-for-each-block.html?topic=nyc_bjc%2F2-conditionals-abstraction.topic&course=bjc4nyc.html&novideo&noassignment
0 Response to "Draft Unit 2 Lab 2 Using Variables and Data Structures to Make Art Page 4 Key"
Postar um comentário