#coding:gbk
#9-1餐馆
class Restaurant(object):
"""一个典型的餐馆"""
def __init__(self, name, cuisine_type):
"""初始化属性name和cuisine_type"""
self.name = name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
"""描述饭店的名字的种类"""
print("\nThe restaurant name is: " + self.name.title())
print("The restaurant type is: " + self.cuisine_type)
def open_restaurant(self):
"""描述正在营业"""
print(self.name.title() + " is oppening, welcome!")
restaurant = Restaurant('queen', 'chinese food')
print(restaurant.name)
print(restaurant.cuisine_type)
restaurant.describe_restaurant()
restaurant.open_restaurant()
#9-2三家餐馆
restaurant = Restaurant('west cateen', 'cheese')
restaurant.describe_restaurant()
restaurant = Restaurant('easr cateen', 'salty')
restaurant.describe_restaurant()
restaurant = Restaurant('middle cateen', 'meat')
restaurant.describe_restaurant()
#9-3用户
class User():
"""存储用户信息"""
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
def describe_user(self):
"""打印用户信息摘要"""
print("\nUser's name is: " + self.first_name.title(
Python编程从入门到实践第9章习题答案
最新推荐文章于 2025-05-03 09:07:35 发布