Curriculum to teach 9 year old girl python. It works. This exact lesson has been tested multiple times with a 9 year old girl. It is known to work and was continually refined whenever she encountered a problem. This method is based on a series of repetitive drills and is part of the PyChildren video series. Links to the first three lessons are included at the end of the deck.
2. Blank Screen
1) import pygame and sys libraries
2) initialize pygame (hint: pygame. )
3) set size of main game screen to 480 by 320 (hint: size = )
4) load screen display (hint: screen = pygame.display. )
5) while loop (tip: indent everything under this)
6) for event loop (tip: pygame.event.get())
7) check for game quit. (hint: if event.type == )
8) quit pygame
9) exit system
10) update display (hint: pygame.display. )
3. Map Load
Above while loop insert the line below
Change map_name to the actual name of
your map file.
map = pygame.image.load("map_name.png")
4. Map Show
In while loop
Indent one tab and insert the code in the pink box
immediately above the line
pygame.display.update()
screen.blit(map, (0, 0))
5. Set Map x and y Variables
Above while loop
map_x = 0
map_y = 0
6. Use Variables for Map Position
In while loop, edit map blit statement
old: screen.blit(map, (0, 0))
new: screen.blit(map, (map_x, map_y))
Replace the line above with the line below.
7. Move Map
In while loop add the code in the pink box to
move the map to the left, making the girl
appear to move the right.
Place below for loop code block
map_x = map_x - 1
8. Create Variable for Direction
Insert line below above while loop
direction = “right”
9. If Direction and Move
In while loop
Indent one tab and insert the two lines in the pink box
below the for loop code block - below sys.exit()
if direction == “right”:
map_x = map_x -1
10. if Statements for all 4 Directions
if direction == “right”:
map_x = map_x -1
Use the two lines below as an example and create if statements for left, up,
and down. Test the game after you create each direction by changing the
direction variable near the top of your program code.
direction = “right”
In your code, edit the line below to test each direction.
11. Keyboard Input - Down
In while loop, find for event loop. It looks like the code
in the blue box. Once you find it, put the code in the pink
box below it with one indent past the for.
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
direction = "down"
for event in pygame.event.get():
12. Test Keyboard Input
direction = “up”
At the top of your code, set the initial direction to “up”
Run the game. After the map starts moving, press the down
arrow on your keyboard.
13. 4 Direction Keyboard Input
Using the two lines of code below as an
example, create if statements for up, right, and
left.
if event.key == pygame.K_DOWN:
direction = "down"
Test your program after you set each direction.
14. Girl Load
Above while loop, insert the line below
girl= pygame.image.load("girl.png")
15. Girl Show
In while loop
Indent one tab and place line in pink box above
pygame.display.update()
and below screen.blit(map, (map_x, map_y)
screen.blit(girl, (100, 100))
Adjust the numbers 100, 100 so that the girl is in the center
of the screen.
16. Bounds Detection
Edit move statements
if direction == "left":
if map_x < 0:
map_x = map_x + 1
if direction == "up":
if map_y < 0:
map_y = map_y + 1
17. Right Boundary
if direction == "right":
if map_x > -1216 + 480:
map_x = map_x - 1
1216 is the width of the map. Change the number if the
map is bigger or smaller.
480 is the width of the screen.
18. Down Boundary
if direction == "down":
if map_y > -896 + 320:
map_y = map_y - 1
896 is the height of the map. Change the number if the
map is bigger or smaller.
320 is the height of the screen.
22. import pygame, sys
pygame.init()
size = (480, 320)
screen = pygame.display.set_mode(size)
map = pygame.image.load("caitlyn_map.
png")
girl = pygame.image.load("girl.png")
map_x = 0
map_y = 0
direction = "up"
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
direction = "down"
if event.key == pygame.K_UP:
direction = "up"
if event.key == pygame.K_RIGHT:
direction = "right"
if event.key == pygame.K_LEFT:
direction = "left"
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if direction == "left":
if map_x < 0:
map_x = map_x + 1
if direction == "up":
if map_y < 0:
map_y = map_y + 1
if direction == "down":
if map_y > -896 + 320:
map_y = map_y - 1
if direction == "right":
if map_x > -1216 + 480:
map_x = map_x - 1
screen.blit(map,(map_x,map_y))
screen.blit(girl, (240-32,160-32))
pygame.display.update()
23.
24. Target Students
9 year old girl
Completed the following drills at least 5 times per drill over
several months:
● The Blank Screen
● The Stationary Square
● The Moving Square
25. Alternate Lessons
If the student is older than 9 and has a mobile phone,
suggest these:
● Mouse and Touchscreen Control
● Going Mobile - Python on Android