Exercise 1:
class Card():
def __init__(self,num,password,ban):
self.num = num
self.password = password
self.__ban = ban
def getBan(self,num,password):
if num == self.num and password == self.password:
return self.__ban
else:
print("Wrong password")
card = Card("1001","123456",500)
print(card._Card__ban)
#print(card.getBan("1001","123456"))
Exercise 2:
class Animal(object):#inherite from object
def __init__(self,color):
self.color = color
def sing(self):
print("Animal is singing")
class Cat(Animal):
pass
class Dog(Animal):
def __init__(self,name,age,color):
#Animal.__init__(self,color)#call init of its parent class
super(Dog,self).__init__(color)
self.name = name
self.age = age
def sing(self):
print("Wof wof singing")
#Animal.sing(self)
super().sing()
dog = Dog("little black",3,"black")
dog.sing()
Exercise 3:
class Animal(object):
def __init__(self, name):
self.name = name
def sing(self):
print("Animal is singing")
class Dog(Animal):
def sing(self):
print("Wof wof singing")
class Cat(Animal):
def sing(self):
print("Mew mew singing")
def testSing(obj):
obj.sing()
#a = Animal("little black")
a = Dog("little black")
testSing(a)
[…] 52 Library Management System (Part 1)| |____Unit 53 Library Management System (Part 2)| |____Unit 54 Object Oriented Advanced| |____Unit 55 Modules|____Python Level 6| |____Unit 56 Windows and Basic Graphics| |____Unit 57 […]