Program Arcade GamesWith Python And Pygame
Lab 4: Loopy Lab
4.1 Part 1
Write a Python program named part_1.py that will print the following:
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
Tips for Part 1
- Generate the output for part one using two nested for loops.
- Create a separate variable to store numbers that will be printed.
This problem requires a bit of an “a-ha” to get. Make sure to ask around if you have problems. My students often find it to be one of the harder problems in this course.
4.2 Part 2
Write a program named part_2.py that:
- Takes a list of five numbers from the user
- Prints the list
- Prints the average
- Modifies the list so each element is one greater than it was before
- Prints the modified list
Example:
Part 2 Enter 5 numbers: Enter a number: 4 Enter a number: 8 Enter a number: 2 Enter a number: 3 Enter a number: 5 You entered: [4, 8, 2, 3, 5] The average of those numbers is: 4.4 That same list with 1 added to each number: [5, 9, 3, 4, 6]
Tips for Part 2
- Allow the user to enter a number.
- Add the number to a list.
- At the end of the loop, print the list.
- Use a loop to total all numbers entered. (Yes, there is a sum command, but practice using the for loop please.
- Divide the total by five to get the average.
- Use a loop to add one to each number in the list
- Print the resulting list (with the 1 added to each element).
This part demonstrates how to create a list, how to total a list, and how to change each item in a list.
4.3 Part 3
Start with the pygame template code:
pygame_base_template.py
Rename the file to part_3.py. Use nested for loops
to draw small green rectangles. Make the image look like Figure 26.1.

Do not create the grid by drawing lines, use a grid created by rectangles.
If this is too boring, create a similar grid of something else. It is ok to change the color, size, and type of shape drawn. Just get used to using nested for loops to generate a grid.
You are not logged in. Log in here and track your progress.
English version by Paul Vincent Craven
Russian version by Vladimir Slav
Turkish version by Güray Yildirim