9-1 餐馆:
class Restaurant():
"""docstring for Restaurant"""
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type=cuisine_type
def describe_restaurant(self):
print(self.restaurant_name,self.cuisine_type)
def open_restaurant(self):
print("The restaurant is opening")
restaurant=Restaurant('bobo_restaurant','delicious')
print(restaurant.restaurant_name,restaurant.cuisine_type)
restaurant.describe_restaurant()
restaurant.open_restaurant()
运行结果:
9-2 三家餐馆:
restaurant1=Restaurant("lmd_restaurant",'good')
restaurant1.describe_restaurant()
restaurant2=Restaurant("hyk_restaurant",'very good')
restaurant2.describe_restaurant()
restaurant3=Restaurant("kq_restaurant",'so good')
restaurant3.describe_restaurant()
运行结果:
9-3 用户:
class User():
"""docstring for User"""
def __init__(self, first_name,last_name,age):
self.first_name = first_name
self.last_name = last_name
self.age = age
def describe_user(self):
print("This is "+self.first_name.title()+' '+self.last_name.lower()+',ages '+str(self.age))
def greet_user(self):
print('Hello '+self.first_name.title()+' '+self.last_name.lower())
-
def deal(usr):
usr.describe_user()
usr.greet_user()
usr1=User('Ke','sibo',21)
deal(usr1)
usr2=User("Lao",'madong',20)
deal(usr2)
usr3=User("kuang",'qian',20)
deal(usr3)
运行结果: