Basics of Python
Activity flow | Slide No | Topic | Time |
---|---|---|---|
TA | 4 | Quiz | 3 min |
5 | Revision | 3 min | |
6 | Datatypes | 3 min | |
7 | Operators | 5 min | |
8 | Modules | 3 min | |
9 | Pygame module | 2 min | |
SA | 10 | Installing pygame module | 3 min |
TA | 11-15 | Creating the screen | 7 min |
SAA1 | 16 | Creating screen with different dimensions | |
SAA2 | 17 | Solving equation | |
Quiz time!!
x=5
7=y
print(x+y)
SyntaxError: cannot assign to literal
12
NameError: name 'y' is not defined
No output but no error thrown
What would be the output of the following code:
Revision time
Importance of programming
Python
Spyder
Input
Output
Function
5
x
Functions
Variables
Variables
(int)
(float)
(bool)
(str)
Integer
Floating point
Boolean
String
Operators
Modules
Pic of pencil bag with pens n pencils
Pic of pencil bag with color pens
pip install pygame
import pygame
Keyword
Pic of pencil bag with pens n pencils
Pic of pencil bag with color pens
Creating the screen:Importing and initializing pygame
import pygame# Importing the module
pygame.init()# Initializing the entire module
R | G | B |
---|---|---|
255 | 255 | 255 |
36 | 90 | 190 |
0 | 176 | 240 |
255 | 0 | 0 |
255 | 100 | 0 |
255 | 255 | 0 |
import pygame
pygam.init()
WHITE = 255,255,255
DARKBLUE = 36,90,190
LIGHTBLUE = 0,176,240
RED = 255,0,0
ORANGE = 255,100,0
YELLOW = 255,255,0
Creating the screen:Creating colours
Creating the screen: Defining screen parameters
import pygame
pygame.init()
WHITE = (255,255,255)
DARKBLUE = (36,90,190)
LIGHTBLUE = (0,176,240)
RED = (255,0,0)
ORANGE = (255,100,0)
YELLOW = (255,255,0)
length=600#Define the length
width=600#Define the width
size = length,width#Size stores both length and width
#Create a screen
screen = pygame.display.set_mode(size)#Create the screen
screen.fill(DARKBLUE)#Fill the screen with a color
pygame.display.flip()#Update the screen
Creating the screen: Setting the screen with user interaction
import pygame
pygame.init()
WHITE = (255,255,255)
DARKBLUE = (36,90,190)
LIGHTBLUE = (0,176,240)
RED = (255,0,0)
ORANGE = (255,100,0)
YELLOW = (255,255,0)
length=600
width=600
size = length,width
screen = pygame.display.set_mode(size)
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(DARKBLUE)
pygame.display.flip()