G12_C10
Functions
pack ()
Activity Flow | Slide No. | Topic | Time |
---|---|---|---|
TA | 4-7 | Revision + quiz | 3 min |
9-13 | Function introduction | 5 min | |
14-21 | Teacher Activity - Coding | 15 | |
SA | 22-28 | Student activity | 5 min |
Wrap - Up | 29-32 | Quiz | 1 min |
SAA | 33-36 | Additional Activities | 5 min |
Class Structure
Slide No. | Topic |
---|---|
15, 16, 20 | Teacher activity coding |
38 | Activity Links Table |
Preparation and Reference
Prerequisites
FOR STUDENTS
-
Computer with an Internet connection.
-
Spyder IDE installed.
-
"pygame" package installed.
-
The latest browser installed.
FOR TEACHER
-
Computer with an Internet connection.
-
The latest browser installed.
-
"pygame" package installed.
-
Spyder IDE installed.
What we did in the last class?
(WARM-UP QUIZ)
Q.1
Which of the following options has a key-value pair?
List
1
Variable
2
Dictionary is defined as follows:
{ key1: value1, key2: value2}
4
Dictionary
3
String
Dictionary
4
Q.2
How to create an infinite scrolling image?
Resetting the image to the original position will make an illusion that the image is infinitely long.
4
By changing its behavior.
3
By using an infinitely long
image.
1
By resetting the image to the original position after moving it to some distance.
1
By resetting the image to the original position after moving it to some distance.
2
By creating a scroller.
Are you all ready to start today's class?
Let's move ahead
-
Take left.
-
Take right.
-
Take left.
-
Take left.
Beach
Parking
Stadium
Take left
Take right
Take left
Take right
-
Take left
-
Take right
-
Take left
-
Take left
-
Take left
-
Take right
-
Take left
-
Take left
Parking
Beach
Stadium
Function
Prepare Tea
Prepare Salad
Prepare Rice
Prepare Icecream
def cooking():
The Flying Bird
B
B
Step 1: Create a "speed" variable and a function named "gravity".
Step 2: Add code inside the "gravity()" function to add gravity to the bee.
Function to add gravity
B
Step 3: Increase the speed of the falling bird.
Global Scope
Local Scope
The Global Keyword and Scope
B
Global and Local Scope
tea =10
def bedroom():
coffee=5
Global variable: Not created inside any function or block.
Local variable: Created inside any function or block.
B
Scope
Creating a variable in Python/Creating the "tea: tea = value"
tea =10
def bedroom():
global tea
tea=tea+5
B
Step 4: Access the global "speed" inside the gravity() function.
The Flappy Bird
B
Task:
1. Create a "flap()" function.
2. The "flap()" function will make the bird jump.
3. Make the bird jump only when the spacebar key is
pressed.
B
Task: Create the "flap()" function
Hints:
1. Define the "flap()" function:
2. Access the global variable "speed" inside "flap()".
3. Change the value of speed to change the movement of bird:
B
Step 1: Create the "flap()" function.
B
Task: Call the "flap()" function when the spacebar key is pressed.
Hints:
1. Check if the spacebar key is pressed:
2. Call the flap() function:
B
Step 2: Check if the spacebar key is pressed and then call the flap() function.
Which keyword is used to define a function?
B
class
def
func
Q.1
A
def
B
C
The syntax for creating a function is as follows:
def functionName():
Here, "def" is a keyword.
function
D
What should be added on line 5 to make the code work?
C
global a
global b
global sum
Q.2
A
B
global sum
C
global sum.
The sum that is created inside show() is local. So, the "print" function will not access it. We have to use the global sum to specify that sum is global so that print() can show the correct value.
a=30
b=60
sum=0
def show:
sum=a+b
print(sum)
ADDITIONAL ACTIVITY-1
Task: Make the bird flap on press of the up arrow key.
Hint:
1. Check if the up arrow key is pressed.
2. Call the "flap()" function.
B
Step 1: Create the function to show the speed on the console.
Activity | Activity Name | Link |
---|---|---|
Teacher Activity 1 | Bee 1 | |
Teacher Activity 2 | Bee 2 | |
Teacher Activity 3 | AA1 Solution | |
Teacher Activity 4 | AA2 Solution | |
Student Activity 1 | Bee 1.5 | |
Additional Activity 1 | Bee 1.5 | |
Additional Activity 2 | Bee 1.5 |
Links Table
G12-C10
By anjali_sharma
G12-C10
- 159