当前位置:   article > 正文

Python编程从入门到实践-练习9-1_python编程从入门到实践练习题

python编程从入门到实践练习题

9-1餐馆:1.创建一个名为Restaurant的类,其方法__init__()设置两个属性:restaurant_name和cuisine_type.创建一个名为describe_restaurant()方法和一个名为open_restaurant()的方法,其中前者打印前述两项信息,而后者打印一条消息,指出餐馆正在营业.
2.根据这个类创建一个名为restaurant的实例,分别打印其两个属性,再调用前述两个方法。

  1. class Restaurant():
  2. def __init__(self, restaurant_name, cuisine_type):
  3. self.restaurant_name = restaurant_name
  4. self.cuisine_type = cuisine_type
  5. def describe_restaurant(self):
  6. print("\n这家餐馆的名字是" + self.restaurant_name.title() + ",主打的菜系是" + self.cuisine_type + '。')
  7. def open_restaurant(self):
  8. print("This restaurant is opening.")
  9. restaurant = Restaurant('四方阁', '川菜')
  10. restaurant.describe_restaurant()
  11. restaurant.open_restaurant()
  12. restaurant_1 = Restaurant('云水谣', '粤菜')
  13. restaurant_1.describe_restaurant()
  14. restaurant_1.open_restaurant()
'
运行

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/992896
推荐阅读
相关标签
  

闽ICP备14008679号