练习9.1
class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
"""初始化属性"""
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
"""打印名称和类型"""
print("The restaurant's name is " + self.restaurant_name.title() + " which are specialize in " + self.cuisine_type + ".")
def open_restaurant(self):
"""打印开业消息"""
print("The restaurant is opening!")
restaurant = Restaurant('john', "french cuisine")
print("\nRestaurant name: " + restaurant.restaurant_name)
print("\nSpecializes in: " + restaurant.cuisine_type)
restaurant.describe_restaurant()
restaurant.open_restaurant()
restaurant_john = Restaurant('taylor','salad')
restaurant_john.describe_restaurant()
restaurant_spicy = Restaurant('zhoumapo', 'Sichaun cuisine')
restaurant_spicy.describe_restaurant()
restaurant_kfc = Restaurant('kfc','fast food')
restaurant_kfc.describe_restaurant()
class User():
def __init__(self,first_name,last_name,age,location):
"""设置初始属性"""
self.first_name = first_name
self.last_name = last_name
self.age = age
self.location = location
def describe_user(self):
"""打印用户信息摘要"""
print("\nFirst Name: " + self.first_name.title())
print("Last Name: " + self.last_name.title())
print("Age: " + str(self.age))
print("Location: " + self.location)
def greeter_user(self):
"""向用户发出个性问候"""
print("Nice to meet you, " + self.first_name.title() + " " + self.last_name.title() + "!")
user1 = User('john','su',20,'Amoy')
user2 = User('talor','swift',29,'New York')
user3 = User('avirl','lavigne',36,'Toronto')
user1.describe_user()
user1.greeter_user()
user2.describe_user()
user2.greeter_user()
user3.describe_user()
user3.greeter_user()