Program Arcade Games
With Python And Pygame

Language
English
Dutch - Nederlands
French
Hungarian - Magyar
Portuguese - Português
Russian - Русский
Spanish - Español
Turkish - Türkçe

Lab 6: Loopy Lab

Each part of this lab is worth 5 points. Complete as many parts as you like for up to 20 points.

6.1 Part 1

Write a Python program 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

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.

6.2 Part 2

Create a big box out of n rows of little o's for any desired size n. Use an input statement to allow the user to enter the value for n and then print the properly sized box.

E.g. n = 3						
oooooo
o    o
oooooo

E.g. n = 8
oooooooooooooooo
o              o
o              o
o              o
o              o
o              o
o              o
oooooooooooooooo

6.3 Part 3

Print the following for any positive integer n. Use an input statement to allow the user to enter the value for n and then print the properly sized box.

E.g. n = 3				

1 3 5 5 3 1 				
3 5     5 3				
5         5				
5         5				
3 5     5 3				
1 3 5 5 3 1			

E.g. n = 5				
1 3 5 7 9 9 7 5 3 1
3 5 7 9     9 7 5 3
5 7 9         9 7 5
7 9             9 7
9                 9
9                 9
7 9             9 7
5 7 9         9 7 5
3 5 7 9     9 7 5 3
1 3 5 7 9 9 7 5 3 1

6.4 Part 4

(This should be a Chapter 7 problem.) Write a program named that:

  1. Takes a list of five numbers from the user
  2. Prints the list
  3. Prints the average
  4. Modifies the list so each element is one greater than it was before
  5. 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 4

This part demonstrates how to create a list, how to total a list, and how to change each item in a list.

6.5 Part 5

Start with the pygame template code:
pygame_base_template.py

Use nested for loops to draw small green rectangles. Make the image look like Figure 30.1.

fig.grid
Figure 30.1: Pygame Grid

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.

About Buy the Book Help Translate My College My Twitter