Recitation 1 — Numbers, Strings, Images
Skills: 1
Reading: 3.1
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 identical T-shirts for a custom design.
 - Then, write a second expression for 7 identical T-shirts for a design.
 - Compare the results.
Hint: Use parentheses where needed: 
(2 * 4) + 4, 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.10to 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.
- 
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 
abovewith each circle and overlaying them onto the rectangle. - Alternatively, overlay them one by one in the correct positions using functions like 
overlay-xy. 
 - 
Challenge
- Can you add a small rectangular “pole” at the bottom?
 - How might you use 
aboveorbesideto 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 
rectangleexpects. 
circle(30, solid, "red")
- Hint: The second argument must be a string (
"solid"or"outline"). 
5. Create a Flag or Shield
Goal: Experiment more with images.
- 
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)).