G11_C6
Activity Flow | Slide No. | Topic | Time |
---|---|---|---|
TA | 3 | Ice-breaker | 1 min |
5-10 | Programming Intro | 2 min | |
11-16 | Object Oriented Programming | 3 min | |
17-22 | Introduction to Python + Spyder + Pygame | 3 min | |
23-28 | TA - Coding | 15 | |
SA | 29-31 | SA | 5 min |
Wrap - Up | 32-36 | Quiz | 1 min |
38 | Additional Activity | 5 min |
Slide No. | Topic |
---|---|
11 | Random number code |
23-25 | Basic pygame code |
31-32 | Making rectangles |
36 | SA Code- Creating enemy rect. |
45 | Additional Activity- Code |
Computer with an Internet connection.
The latest browser installed.
Spyder IDE.
Projector to present the screen.
1. Computer with an Internet connection.
2. The latest browser installed.
for loop
infinitely print 0
for i in range(10):
prod=10*i
while prod<=10:
print(prod)
check again
condition never becomes false!!
for i in range 10:
for loop starts: i=0
prod=10*0=0
prod<=10? : True
prod which is "0" is printed
Revise!!
carryOn = True
while carryOn:
for event in pygame.event.get():
if event.type == pygame.QUIT:
carryOn = False
pygame.quit()
B
Single value
Multiple values
List
B
12
56
90
Roll No.s:
roll_no=[12,56,90]
Box Brackets
Comma
roll_no=[12,56,90]
print(roll_no)
67
39
List to which we want to append an item
Here: roll_no
append function:
appends one item to list
item to be appended to list
dot operator: helps the append function understand which list it has to work on.
12
56
90
Roll No.s:
roll_no=[12,56,90]
print(roll_no)
roll_no.append(67)
print(roll_no)
roll_no.append(39)
print(roll_no)
remove function:
removes one item to list
item to be removed
from list
dot operator: helps the remove function understand which list it has to work on.
List from which we want to remove
an item
Here: roll_no
90
67
39
Roll No.s:
12
56
90
roll_no=[12,56,90]
print(roll_no)
roll_no.append(67)
print(roll_no)
roll_no.append(39)
print(roll_no)
roll_no.remove(90)
print(roll_no)
Create a list of numbers 1 to 100.
numbers=[1,2,3,4,5,6,...]
numbers=[]
for i in range(1,101):
numbers.append(i)
1.Create an empty list
2. Use a for loop to iterate through desired range.
3.Append the desired element to the created list.
1.Create an empty list
2.Use a for loop to create rectangle object
and add to the empty list
X6 times
bricksR=[]
for i in range(6):
brick=pygame.Rect(10 + i* 100,60,80,30)
red_bricks.append(brick)
Too many steps!!
What item to append?
How many times to append?
1.Create an empty list
2.Use a for loop to create rectangle object
and add to the empty list
X6 times
bricksR=[pygame.Rect(10 + i* 100,60,80,30) for i in range(6)]
for i in bricksR:
pygame.draw.rect(screen,RED,i)
Code to be able to see the orange bricks on the screen
bricksO=[pygame.Rect(10 + i* 100,100,80,30) for i in range(7)]
for i in bricksO:
pygame.draw.rect(screen,ORANGE,i)
ORANGE = [255,100,0]
Remove brick
Since 10 is not present it will throw us a value error.
num=[2,3,4,6,7]
num.remove(10)
print(num)
Code to be able to see the yellow bricks on the screen
bricksY=[pygame.Rect(10 + i* 100,140,80,30) for i in range(7)]
for i in bricksY:
pygame.draw.rect(screen,YELLOW,i)
YELLOW = [255,255,0]