play with python lecture 2
TRANSCRIPT
![Page 1: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/1.jpg)
Play with PythonLecture 2
![Page 2: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/2.jpg)
Agenda
Revision
Object Oriented Programming
Demo 1
Demo 2
Demo 3 (GUI)
Assignment
Next Week !
![Page 3: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/3.jpg)
Revision
Lists
empty list:
lst = []
list of lists:
lofl = [[1,2],[3,4]]
list of different types: lst2 = [1, "hi"]
Dictionary:
empty dictionary:
d = {}
![Page 4: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/4.jpg)
Object Oriented Programming
Application is a set of objects
![Page 5: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/5.jpg)
Object Oriented Programming
Application is a set of living objects
![Page 6: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/6.jpg)
Object Oriented Programming
Application is a set of living interacting objects
![Page 7: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/7.jpg)
Object Oriented Programming
Application is a set of living interacting objects
![Page 8: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/8.jpg)
Data + Behaviour
Application is a set of living interacting objects
![Page 9: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/9.jpg)
Demo 1 (Animals)
c = Cat()
c.talk()
c.walk()
![Page 10: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/10.jpg)
Demo 1 (Animals)
c = Cat()
c.talk()
c.walk()
d = Duck()
d.talk()
d.fly()
![Page 11: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/11.jpg)
Demo 1 (Animals)
c = Cat()
c.talk()
c.walk()
d = Duck()
d.talk()
d.fly()
m = Mouse()
m.die()
![Page 12: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/12.jpg)
Demo 1 (Animals)
c = Cat()
c.talk()
c.walk()
d = Duck()
d.talk()
d.fly()
m = Mouse()
m.die()
![Page 13: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/13.jpg)
Demo 1 (Animals eating)
c = Cat()
c.talk()
c.walk()
c.eat(m)
c2 = Cat()
c2.eat(b)
![Page 14: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/14.jpg)
Demo 1 (Animals)
c = Cat()
c.talk()
c.walk()
c.eat(m)
c2 = Cat()
c2.eat(b)
m = Mouse()
b = Bread()
![Page 15: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/15.jpg)
Demo 1 Classes (Animals)
class Cat:
def talk(self):
print "ميااو"
def walk(self):
print " تك تك " تك
def eat(self, something):
something.die()
print " لذييذ ، ايم " يا
class Mouse:
def die(self):
print " !! ،آآآآآه"النجدة
class Bread:
def die(self):
print “” كراش”كراش
![Page 16: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/16.jpg)
Demo 1: ِ�List of Animals
animals = []
animals.append(Cat())
animals.append(Duck())
for a in animals:
a.talk()
animals list is also an object of class "List" !
![Page 17: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/17.jpg)
Demo 2 (Computer Device)
![Page 18: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/18.jpg)
Demo 2 (Computer Device)
class Computer:def __init__(self, computer_type, basePrice):
self.computerType = computer_type
Constructor
Member
![Page 19: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/19.jpg)
GUI with PyQt4
![Page 20: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/20.jpg)
GUI Exampledlg = QDialog()
btn = QPushButton("Click Me !", dlg)
btn.clicked.connect(onButtonClicked)
btn2 = QPushButton("Click Me Too !!", dlg)
btn2.move(100,0)
btn2.clicked.connect(onButton2Clicked)
dlg.show()
def onButtonClicked():
print "Hello World"
def onButton2Clicked():
btn.close()
![Page 21: Play with python lecture 2](https://reader036.vdocuments.mx/reader036/viewer/2022062312/555a66a0d8b42a972b8b4859/html5/thumbnails/21.jpg)
GUI Example (Added an image)dlg = QDialog()
dlg.resize(500, 500)
btn = QPushButton("Click Me !", dlg)
btn.clicked.connect(onButtonClicked)
btn2 = QPushButton("Click Me Too !!", dlg)
btn2.move(100,0)
btn2.clicked.connect(onButton2Clicked)
label = QLabel("My First GUI program", dlg)
pix = QPixmap("Water lilies.jpg")
label.setPixmap(pix)
dlg.show()
def onButtonClicked():
print "Hello World"
def onButton2Clicked():
btn.close()