蟒蛇书:python编程:从入门到实践
习题9.1至9.3
#9-1
class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name=restaurant_name
self.cuisin_type=cuisine_type
def describe_restaurant(self):
print("restaurant:"+self.restaurant_name+"\ncuisin_type:"+self.cuisin_type)
def open_restaurant(self):
print('The restaurant is open')
restaurant=Restaurant('xiao','kuai')
restaurant.describe_restaurant()
restaurant.open_restaurant()
#9-2
restaurant1=Restaurant('da','man')
restaurant2=Restaurant('Xiao','Kuai')
restaurant3=Restaurant('Da','man')
restaurant1.describe_restaurant()
restaurant2.describe_restaurant()
restaurant3.describe_restaurant()
#9-3
class 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('name:'+self.first_name+' '+self.last_name+'\nage:'+self.age)
def greet_user(self):
print('hello')
user=User('z','f','23')
user.describe_user()
user.greet_user()