A5 — Introduction to lists and review

Practice using lists.

Due Sep 30, 2026

Estimated time to complete (just the assignment, excluding the prep materials): 40–80 min.

Prep materials: Week 5: Introduction to lists and review.

What to do

Create a file a5.arr and add all your code there. Remember to test that the file runs before submitting; double check the context and names. Submit the file to Assignment 5 Submission on Brightspace.

  1. Define the name rect-perim-1 to be the perimeter of a rectangle with sides 4 and 7.

  2. Define a check-block named check-rect-perim-1 to check that rect-perim-1 is correct.

  3. Define a function named sign that takes a number and returns 0.

  4. Define a check-block named check-sign to check that the sign function returns 1 if the number is positive, -1 if the number is negative, and 0 if the number is zero. Do these tests fail? Do any of them pass?

  5. Change the implementation of sign to return 1 if the number is positive, -1 if the number is negative, and 0 if the number is zero. Do the tests in check-sign pass now?

  6. Define a function named gen-shape (along with a check-block named check-gen-shape) that takes a string with the name of the shape, a color string, and a size number, and returns a corresponding image with the solid filling.

    • The shape can be one of “circle”, “square”, “triangle”, and the shape description is case-insensitive (meaning, both “CirCLE” and “circle” are valid).
    • If the given shape is anything else, the function should throw an error.
      Note: to check that a function call throws an error, you can use raises "" in your check-block, e.g., 5 / 0 raises "".
  7. Define the name list-sizes to be a list of numbers 10, 15, 20, 25, 30. Hint.

  8. Define the name list-el-first to be the first element of list-sizes.

  9. Define the name list-sqrts to be a list of the square roots of the elements of list-sizes. Do not build the list manually. Hint.

  10. Define a check-block named check-list-sqrts to check that the length of list-sqrts is the same as the length of list-sizes, and that at least one element of list-sqrts has the correct value.

  11. Define the name list-squares to be a list of solid blue squares with the side lengths given by the elements of list-sizes. Do not build the list manually.

  12. Define the name list-shape-names to be a list of "circle", "triangle", "square", "triangle", "circle".

  13. Define a function named gen-shapes (along with a check-block named check-gen-shapes) that takes a list of shape names and a color string, and returns a list of corresponding images with the solid filling, where the size parameter for each shape is 16.

  14. Define the name list-shapes to be the result of calling gen-shapes with list-shape-names and "green".

  15. Recover the games table from Assignment 3 and define the name list-game-names to be a list of the names of the games in the table.

Grading

Auto-graded for correctness, with named check-blocks auto-graded for coverage.