Week 3 Do Now Questions Question: In this setup procedure the

advertisement
Week 3 Do Now Questions
1. Question: In this setup procedure the programmer intended to create one turtle of each
color: red, green, and blue. What went wrong?
to setup
clear-all
create-turtles 1 [ set color [ 255 0 0 ] ]
create-turtles 2 [ set color [ 0 0 255 ] ]
create-turtles 3 [ set color [ 0 255 0 ] ]
end
a)
b)
c)
d)
color indexes should be used;
***too many turtles were created;
the turtles are not red, green and blue;
no errors are present
Each create-turtles command creates as many turtles as shown in the first argument.
This procedure makes 1 then 2 then 3 turtles for a total of 6 turtles.
2. Question: Given the binary number 1110, what is the result of shifting it 4 times?
a) The result is equal to 4 X 1110 = 4440;
b) The result is equal to 11,100,000;
c) The result is equal to 14 X 4 = 56;
d) ***The result is equal to 14 X 16 = 224
The binary number above is 14 (decimal). Left shifting a binary number is
equivalent to multiplication. Left shifting by 4 is the same as multiplying by 24
or 16. We do this in our decimal system when we quickly multiply numbers by
10 or 100—simply moving the decimal point.
3. Question: In RGB colors, three bytes are used to represent the amount of each base
color (R, G, B) goes into making the new color. How many possible unique colors are
there using this color scheme?
a)
b)
c)
d)
***More than 16 million unique colors;
24 unique colors;
8 X 8 X 8 = 512 unique colors;
24 X 24 X 24 unique colors
8 x 8 x 8 for Red
8 x 8 x 8 for green
8 x 8 x 8 for Blue
Document1
Page 1 of 4
89 = 134217728
4. Question: What happens when two infinite go procedures (forever buttons) are
executed at the same time after one turtle is created in a setup procedure?
to go1
ask turtles
[
forward 26
right 155
]
end
to go2
ask turtles
[
forward 40
right 175
]
end
a) One turtle executes the go1 procedure and one turtle executes the go2
procedure;
b) One turtle executes only the first go procedure;
c) The go procedures cancel each other out;
d) ***The turtle executes each go procedure one at a time.
All procedures that are executing will get a turn. If you have a question about how
something is going to execute, modify code slighty so that it shows what is going
on:
Document1
Page 2 of 4
5. Question: Which of the following patterns does this procedure make?
to draw-it
pen-down
let myCount 20
while [ myCount > 0 ]
[
forward myCount
right 90
set myCount myCount - 2
]
end
a)
b)
c)
d)
A 10 sided polygon
A 5 sided polygon or pentagon
***A square spiral
A zigzagging line
6. Question: In this procedure the programmer wanted the turtle to draw a tight spiral.
What went wrong?
to draw-it
pen-down
let myCount 20
while [ myCount > 0 ]
[
forward myCount
left 60
]
set myCount myCount - 1
end
a)
b)
c)
d)
It drew a loose spiral;
It drew a triangle then stopped;
***It ran on forever without spiraling;
Nothing, it drew a tight spiral.
Always remember to decrement (fancy word for “make smaller”) your counter (myCount)
INSIDE the loop. Common programming error #102.
Document1
Page 3 of 4
7. Question: In this procedure the programmer wanted the turtle to draw a rosette made up
of circles. Instead it made a column of circles. What should be changed to make a
rosette?
to draw-it
pen-down
repeat 36
[
repeat 36
[
forward 1
right 10
]
forward 1
]
end
a)
b)
c)
d)
Change the inner “repeat 36” to a “repeat 35”
Change the last “forward 1” to a “right 10”;
Change the “right 10” to a “right 9”;
***Either a or b above.
Problems like this are easy if you just program them. Otherwise you need to notice that 36 is
a clue. SAT questions will often have “clues” like this. 36 x 10 = 360 degrees. The turtle has
the same heading at the conclusion of each circle—you’ll get a line of circles. Changing inner
36 to 35 will create a bunch of partial circles offset by 10 degrees.
Document1
Page 4 of 4
Download