9-1餐馆
9-2三家餐馆
9-3用户
9-6冰淇淋小店
class restaurant():
def __init__(self,restaurant_name,cusine_type):
self.name = restaurant_name
self.type1 = cusine_type
def describe_restaurant(self):
print ("The name of the restaurant is " + self.name + "and the type is " + self.type1)
def open_restaurant(self):
print ("The restaurant is open~")
res = restaurant("Bob's" , 'Chinese food')
res.describe_restaurant()
res.open_restaurant()
9-2三家餐馆
class restaurant():
def __init__(self,restaurant_name,cusine_type):
self.name = restaurant_name
self.type1 = cusine_type
def describe_restaurant(self):
print ("The name of the restaurant is " + self.name + "and the type is " + self.type1)
def open_restaurant(self):
print ("The restaurant is open~")
res = restaurant("Bob's" , 'Chinese food')
res2 = restaurant("LALALA" , 'Italian food')
res3 = restaurant("HAHAHA" , 'Franch food')
res.describe_restaurant()
res2.describe_restaurant()
res3.describe_restaurant()
9-3用户
class user():
def __init__(self,first_name,last_name,age):
self.firstname = first_name
self.lastname = last_name
self.age = age
def describe(self):
print ("The name of the user is " + self.firstname.title() + ' ' + self.lastname.title() + "and the age is " + str(self.age))
def greet(self):
print ("Hello," + self.firstname.title() + ' ' + self.lastname.title())
auser = user("Lucy","Zheng",20)
auser.describe()
auser.greet()
9-6冰淇淋小店
class restaurant():
def __init__(self,restaurant_name,cusine_type):
self.name = restaurant_name
self.type1 = cusine_type
def describe_restaurant(self):
print ("The name of the restaurant is " + self.name + "and the type is " + self.type1)
def open_restaurant(self):
print ("The restaurant is open~")
class IceCreamStand(restaurant):
def flavors(self):
varities = ['struburry','blueburry','chocolate','milk']
for name in varities:
print (name)
ice = IceCreamStand ('Lily','Ice cream')
ice.describe_restaurant()
ice.flavors()
9-10导入restaurant类
如图所示
![](https://i-blog.csdnimg.cn/blog_migrate/e0cfe6b360b8472a4b7b466f911f4042.png)
![](https://i-blog.csdnimg.cn/blog_migrate/324956dbe4bd8a93b7efacbe5b7379d2.png)