Constructors
G12_C12_ForTeacher
Text
Activity Flow | Slide No. | Topic | Time |
---|---|---|---|
3-7 | Revision + Quiz | 2 mins | |
8-18 | Introduction to Lists |
12 mins | |
TA | 19-23 | TA-Coding | 10 mins |
SA | 24-29 | Student Activity | 10 mins |
Wrap-Up | 30-32 | Wrap-Up Quiz | 2 mins |
SAA | 33-34 | Additional Activities | 10 mins |
Class Structure
Slide No. | Topic |
---|---|
13 | Lists in python |
20-23 | TA Coding Steps |
36 | Activity Links Table |
Preparation and Reference
TA: Teacher Activity SA: Student Activity SAA: Student Additional Activity
What we did in the last class?
(WARM-UP QUIZ)
Q.1
What should be written in the missing code?
def.
1
global.
2
self.
3
3
self.
self is passed to each method of the class. And self can be used to access the class variables.
class book:
price=10
author="xyz"
def showPrice(self):
print( price);
Class name must be in same case as it is defined
How to create an object of following class?
book1 = Book()
3
2
1
book1 = Book()
book=book()
1
class Book:
price=10
author="xyz"
def showPrice(self):
print(self.price);
Book= book(self)
Q.2
You can go ahead
Classes and Objects
Change with earlier class image
Blueprint for Manufacturing
Annie: Delhi
Sam : Noida
Jack : Gurgram
John : Gurgram
Class
(blueprint)
Objects
Factory
Customer can choose some properties of car like color, engine etc.
How cars are different when same blueprint is used?
Blueprint for Manufacturing
Annie: Delhi
Sam : Noida
Jack : Gurgram
John : Gurgram
Class
(blueprint)
Objects
Color: Red
Engine: Petrol
Music yes
Constructor
Passing arguments
Annie: Delhi
Sam : Noida
Jack : Gurgram
John : Gurgram
p3 = Platform(80,150)
p1 = Platform(100,100)
p2 = Platform(120,80)
Passing arguments
Annie: Delhi
Sam : Noida
Jack : Gurgram
John : Gurgram
pipe1 = Pipe(100)
pipe2 = Pipe(300)
Passing arguments
Annie: Delhi
Sam : Noida
Jack : Gurgram
John : Gurgram
pipe1 = Pipe(100)
class Pipe:
var xposition
def __init__(self,x):
xposition=x
How to Position the top/bottom pipes
Annie: Delhi
Sam : Noida
Jack : Gurgram
John : Gurgram
Seat reservation
Change with earlier class image
I have left with one name plate only
John and Sameer are coming can you mark their seats.
How can I use one nameplate to guide both
No problem I will ask John to sit on left side of name plate seat and Sammer on the right side.
Positioning
Show john and sameer coming and sitting on left and right side of the seat with name plate
Reserve Seat
Positioning of pipes.
Annie: Delhi
Sam : Noida
Jack : Gurgram
John : Gurgram
Gap
BottomPipe.y= gap+100
topPipe.y= gap-400
100
BottomPipe.y= gap+100
400
Step 1: Create a Pipe class
Steps to complete the activity
Step 2: Create a constructor using __init__() method.
Steps to complete the activity:
Step 3: Create a variable gap and assign random value to it.
Step 4: Create a rect named topPipe in the Pipe class.
Steps to complete the activity:
Step 4: Create pipe1 object
Steps to complete the activity:
Step 4: Add the display function and call it to display the pipes.
Steps to complete the activity:
Oputput:
Good Going Team! Keep up the spirit!
Student Activity- Add a Bottom pipe and another pipe object
Add the bottom pipe
Task: Add the bottom pipe
Hint:
1. Create a rect "bottomPipe" in constructor function.
Note: Make sure bottom pipe is displayed below the gap.
2. Display the pipe image on bottompipe in display() function
Steps to complete the activity:
Create another set of pipe
Task: Add another set of pipes
Hint:
1. Create another Pipe class object
2. Display the pipe2 object using display function
Steps to complete the activity:
In python constructor function us named as __init__
Q.1
Which one of these is a constructor function?
def __init__():
3
2
1
4
def constructor():
init():
def construct():
1
def __init__():
ball = Ball(20) is valid as this class's constructor takes one argument.
Which can be passed while creating the object.
Q.2
Which of these is valid way to create object of the Ball class?
ball= Ball()
3
2
1
4
ball(20)
ball = Ball(20)
Ball(20)
3
ball = Ball(20)
class Ball:
def __init__(self,x):
self.radius=x
ADDITIONAL ACTIVITY - 1
Task: Add another set of pipes
Hint:
1. Create another Pipe class object
2. Display the pipe2 object using display function
ADDITIONAL ACTIVITY - 1
Solution:
Hint: 1. Load the cloud image in the images dictionary
2. Place the cloud image on the screen
ADDITIONAL ACTIVITY - 2
Hint:
1. Increment the bee's x location to move it forward in gravity() function
Task: Make the bee move forward
ADDITIONAL ACTIVITY - 2
Solution:
Hint: 1. Load the cloud image in the images dictionary
2. Place the cloud image on the screen
Links Table
Activity No. | Activity Name | Links |
---|---|---|
Teacher Activity 1 | Bee 3 |
|
Teacher Activity 2 | Bee 4 -SA solution | |
Teacher Activity3 | AA1- Solution | |
Teacher Activity4 | AA2 Solution | |
Student Activity 1 | Bee 3.5 | |
Additional Activity 1 | Bee 3.5 | |
Additional Activity 2 | Bee 3.5 |
G12_C12_FINAL
By anjali_sharma
G12_C12_FINAL
- 98