Recitation 1 -- Numbers, Strings, Images
Outcomes: None
Suggested Recitation Flow
- Warm‐Up (5–10 minutes)
- Solve Problem 1 (T-Shirt Shop Math) to review spacing and parentheses.
- Strings Practice (5 minutes)
- Try Problem 2 (String Surprises) to see different string errors.
- Hands‐On Image Work (15–20 minutes)
- Go through Problem 3 (Traffic Light) for layering shapes.
- Error Debugging (10 minutes)
- Look at Problem 4 (Broken Code Hunt) to interpret type mismatch issues.
- Creative Builds (20 minutes)
- Try Problem 5 (Flag or Shield) or a personal variation.
Problem Set
1. T-Shirt Shop Math
Goal: Practice arithmetic expressions and order of operations.
-
Calculating Cost
- You sell custom T-shirt designs for $12 each. However, every design requires a $3 setup fee.
- Write an expression to calculate the total cost for 5 T-shirts.
- Then, write a second expression for 7 T-shirts.
- Compare the results.
Hint: Use parentheses where needed:
(12 * 5) + 3
, etc.
-
Rectangular Poster
- You also print posters. A client wants a 24" by 36" poster. The price is based on the perimeter of the poster times $0.10.
- First, compute the perimeter with an expression (remember
Perimeter = 2 * (width + height)
). - Then, multiply that perimeter by
0.10
to find the cost. - What happens if you forget parentheses around
(width + height)
?
2. String Surprises
Goal: Experiment with strings.
-
Saving a Tagline
- Your T-shirt shop’s tagline is: “Designs for everyone!”
- Type it into Pyret as a string.
- Now omit one of the quotes and see the error.
- Fix the error so your string prints correctly.
-
Color Inventory
- You keep track of colors as strings. For instance:
"red"
,"blue"
,"gold"
. - What happens if you try to
+
them (e.g."red" + "blue"
)? - Reflect:
+
works on both numbers and strings. What happens if you do1 + "blue"
?
- You keep track of colors as strings. For instance:
3. Make a Traffic Light
Goal: Practice layering shapes in a new way.
-
Frame
- Start with a solid black rectangle that is tall and narrow (e.g.,
rectangle(40, 100, "solid", "black")
). This will be the traffic light’s body.
- Start with a solid black rectangle that is tall and narrow (e.g.,
-
Lights
- Overlay three colored circles (red, yellow, green) on top of that rectangle, spaced in a vertical stack.
- You may do this by carefully using
above
with each circle and overlaying them onto the rectangle. - Alternatively, overlay them one by one in the correct positions if you’re comfortable with more advanced layering.
-
Challenge
- Can you add a small rectangular “pole” at the bottom?
- How might you use
above
orbeside
to position the pole?
4. Broken Code Hunt
Goal: Identify type mismatches or wrong arguments.
Each of these snippets has an error. Try them in Pyret, read the error message, and fix it.
-
# Goal: A rectangle with width 50 and height 20, solid black
rectangle(50, "solid", 20, "black")- Hint: Check the order and types of arguments that
rectangle
expects.
- Hint: Check the order and types of arguments that
-
# Trying to combine a number and a text string
5 + "Thanks"- Hint: Notice what type
+
needs for both operands.
- Hint: Notice what type
-
# Oops, forgot a quote?
circle(30, solid, "red")- Hint: The second argument must be a string (
"solid"
or"outline"
).
- Hint: The second argument must be a string (
5. Create a Flag or Shield
Goal: Encourage creative composition.
-
Flag Design
- Invent a simple flag using at least three shapes.
- For instance, many flags have stripes (rectangles) above or beside each other, or shapes overlaid in the center.
- Example steps:
- Make one large rectangle as the background.
- Overlay a smaller shape (circle, star, or rectangle) in the upper left.
- Possibly add a vertical stripe on the right side.
-
Shield Variation
- Alternatively, make a shield shape (maybe a rotated square to get a diamond) overlaid with a circle or star.
- Try out
rotate(45, square(100, "solid", "gray"))
to get a diamond shape. - Layer shapes on top of it for an emblem.
-
Share
- Show your neighbor.
- If time allows, label your shapes with text (e.g.,
overlay(text("Go!", 20, "black"), your-shield)
).