class logo

CS 122 - Day 4 Exercises

This page lists some problems for today's class. After today, you should be able to solve these problems on your own. Problems with this color are more challenging.

1) Find the Maximum

Use a loop to find the maximum value in a list of numbers.
Download solutions to exercises 1-3

1.a) Find the Minimum

Adapt the above problem to instead find the minimum value in a list.

2) Reverse a List

Use a loop to reverse a list into another list
Download solutions to exercises 1-3

3) Sort a list

Use nested loops to sort a list into another list (by repeatedly finding the maximum value and moving it over). Then copy the sorted list back into the original list so they show up in ascending order.
Download solutions to exercises 1-3

4) Replay movement

Use two lists to record the x and y coordinates of the friction marble as it rolls around the screen. When the space-bar is pressed, use the lists of coordinates to "replay" the balls motion.
Download solutions to exercise 4

5) Conversation

Use the "ask" command in the "Sensing" category to ask the user a question. Use the answer variable and if/else commands to generate a reasonable response

6) Maze

Edit the stage image to have a maze. Add code to the friction marble to have it bounce off of the walls (check if it is touching the color of the maze walls, then alter its direction accordingly, try 360 - direction to get a good new direction).

7) Space Invaders

Recreate the classic game of space invaders. Start with just one enemy sprite, when you get it working you can add more. When you shoot, have a little tiny ball sprite appear as the shot and move up the screen. If it hits something or when it gets to the top have it disappear.