9-1:
class Restaurant():
def __init__(self):
self.name = "fandian"
self.type = "hahaha"
def print(self):
print(self.name + self.type)
def working(self):
print (" restaurant is working now ")
a = Restaurant()
a.print()
a.working()
9-4
class Restaurant():
def __init__(self):
self.name = "fandian"
self.type = "hahaha"
self.number = 0
def print(self):
print(self.name + self.type)
def working(self):
print (" restaurant is working now ")
def set(self,number):
self.number = number
def increment(self):
self.number+= 1
a = Restaurant()
print ( a.number )
a.number = 3
print(a.number)
a.set(6)
print(a.number)
a.increment()
print(a.number)
output: 0 3 6 7
9-6
class Restaurant():
def __init__(self):
self.name = "fandian"
self.type = "hahaha"
self.number = 0
def print(self):
print(self.name + self.type)
def working(self):
print (" restaurant is working now ")
def set(self,number):
self.number = number
def increment(self):
self.number+= 1
class IceCreamStand(Restaurant):
def __init__(self):
super().__init__()
self.flavors = ["a","b","c"]
a = IceCreamStand()
print(a.flavors)
9-10
from first import Restaurant
a = Restaurant()
a.working()