G11_C4
Activity Flow | Slide No. | Topic | Time |
---|---|---|---|
TA | 4-7 | Warm up+Quiz+Revision | 5 min |
8-15 | Understanding loops | 7 min | |
16-21 | Brick Creation | 5 min | |
SA | 22-26 | Orange brick creation | 5 min |
27-31 | Brick-ball collision | 7 min | |
TA | 32 | Precap to next class | 2min |
Wrap - Up | 33-36 | Quiz | 5 min |
SA | 38-40 | Additional Activity | 5 min |
Slide No. | Topic |
---|---|
14 | TA1 solution |
19 | TA2 solution |
21 | TA3 solution |
24 | SA1 solution |
30 | SA2 solution |
40 | SAA1 solution |
1. Computer with an Internet connection.
2. The latest browser installed.
1. Computer with an Internet connection.
2. The latest browser installed.
3. Spyder installed.
4. Projetor to present the screen
x=5
7=y
print(x+y)
Syntax :
variable =value
value= variable
56/8=7
"**" has higher operator precedence than "/" , hence 2**3 gets executed first
print(56/2**3)
B
Please help me keep these boxes from point A to point B so that we can load the truck!
Ok Papa!!
A
A
B
Pick a box from point A and place in point B
A
B
Pick a box from point A and place in point B
5 times.
5!!
How many boxes?
for i in range(5):
#Execute task
i=0 | Execute task once |
1 | Execute once more |
2 | Execute again |
... | ... |
4 | Execute for the 5th time |
for i in range(5):
print(i)
for i in range(start ,stop)
default=0
stops at n-1 if stop=n
80
20
30
10
110
210
310
410
510
height
width
spacing
X-coordinates
How can I get these numbers?!
10
110
210
310
410
510
for i in range(6):
print(i,i*100+10)
Lets code for the red bricks
import pygame
pygame.init()
screen = pygame.display.set_mode((600, 600))
pygame.display.set_caption("Breakout Game")
paddle=pygame.Rect(300,500,60,10)
ball=pygame.Rect(200,250,10,10)
ballx=-1
bally=-1
paddlex=2
carryOn = True
while carryOn:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
carryOn = False # Flag that we are done so we exit this loop
screen.fill((36,90,190))
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
if paddle.x<540:
paddle.x+=paddlex
if event.key == pygame.K_LEFT:
if paddle.x>0:
paddle.x-=paddlex
pygame.draw.rect(screen,(0,176,240),paddle)
ball.x=ball.x+ballx
ball.y=ball.y+bally
if ball.x>=590:
ballx=-ballx
if ball.x<=10:
ballx=-ballx
if ball.y>=590:
bally=-bally
if ball.y<=10:
bally=-bally
if paddle.collidepoint(ball.x,ball.y):
bally=-bally
pygame.draw.rect(screen,(255,255,255) ,ball)
for i in range(6):
brick=pygame.Rect(10 + i* 100,60,80,30)
pygame.draw.rect(screen,(255,0,0),brick)
pygame.display.flip()
pygame.quit()
Now create the orange bricks!
"Draw 'brick' on 'screen' with color orange[RGB:(255,100,0)]"
x: iterate at required with the help of i
y:100
width: 80
height: 30"
import pygame
pygame.init()
screen = pygame.display.set_mode((600, 600))
pygame.display.set_caption("Breakout Game")
paddle=pygame.Rect(300,500,60,10)
ball=pygame.Rect(200,250,10,10)
ballx=-1
bally=-1
paddlex=2
carryOn = True
while carryOn:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
carryOn = False # Flag that we are done so we exit this loop
screen.fill((36,90,190))
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
if paddle.x<540:
paddle.x+=paddlex
if event.key == pygame.K_LEFT:
if paddle.x>0:
paddle.x-=paddlex
pygame.draw.rect(screen,(0,176,240),paddle)
ball.x=ball.x+ballx
ball.y=ball.y+bally
if ball.x>=590:
ballx=-ballx
if ball.x<=10:
ballx=-ballx
if ball.y>=590:
bally=-bally
if ball.y<=10:
bally=-bally
if paddle.collidepoint(ball.x,ball.y):
bally=-bally
pygame.draw.rect(screen,(255,255,255) ,ball)
for i in range(6):
brick=pygame.Rect(10 + i* 100,60,80,30)
pygame.draw.rect(screen,(255,0,0),brick)
for i in range(6):
brick=pygame.Rect(10 + i* 100,100,80,30)
pygame.draw.rect(screen,(255,100,0),brick)
pygame.display.flip()
pygame.quit()
Brick and ball collided?
Brick disappears
Change color of brick to background color
Brick collided with ball??
Now let's code for ball-brick collisions.
Hints:
Change color of brick to the screen fill color
Negate 'bally' to change the direction of the ball
import pygame
pygame.init()
screen = pygame.display.set_mode((600, 600))
pygame.display.set_caption("Breakout Game")
paddle=pygame.Rect(300,500,60,10)
ball=pygame.Rect(200,250,10,10)
ballx=-1
bally=-1
paddlex=2
carryOn = True
while carryOn:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
carryOn = False # Flag that we are done so we exit this loop
screen.fill((36,90,190))
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
if paddle.x<540:
paddle.x+=paddlex
if event.key == pygame.K_LEFT:
if paddle.x>0:
paddle.x-=paddlex
pygame.draw.rect(screen,(0,176,240),paddle)
ball.x=ball.x+ballx
ball.y=ball.y+bally
if ball.x>=590:
ballx=-ballx
if ball.x<=10:
ballx=-ballx
if ball.y>=590:
bally=-bally
if ball.y<=10:
bally=-bally
if paddle.collidepoint(ball.x,ball.y):
bally=-bally
pygame.draw.rect(screen,(255,255,255) ,ball)
for i in range(7):
brick=pygame.Rect(10 + i* 100,60,80,30)
pygame.draw.rect(screen,(255,0,0),brick)
for i in range(7):
brick=pygame.Rect(10 + i* 100,60,80,30)
pygame.draw.rect(screen,(255,100,0),brick)
if brick.collidepoint(ball.x,ball.y):
pygame.draw.rect(screen,(36,90,190),brick)
pygame.display.flip()
pygame.quit()
Why is the brick reappearing when the ball moves away?
for i in range(10):
if i%2==0:
print(i)
i%2 calculates remainder on dividing a number by 2.A remainder 0 would mean the number is even.Hence only the even numbers get printed
num=20
if num/10==2:
for i in range(5):
num+=5
print(num)
20/10 is equal to 2, hence the condition of the loop is satisfied .Hence 20 is incremented by 5 .So it becomes 25 , then 30, then 35, then 40 and final finally 45.
Can you print the values of the multiplication table of 23?
Hints:
23 * 1 = ?
23 * 2 = ?
23 * 3 = ?
.
.
.
.
23 * 10 = ?
for i in range(1,11):
print(23*i)
Activity | Activity Name | Link |
---|---|---|
Teacher Activity 1(S) | For loop_basic (Solution) | |
Teacher Activity 2(S) | For loop_x coordinates (Solution) | |
Teacher Activity 3 | Red brick creation_template | |
Student Activity 1 | Orange brick creation_template | |
Teacher Activity 4 | Orange brick creation (SA1 Solution) |
|
Teacher Activity 5 | Multiplication tables (SAA1 Solution) |