练习题-类-给属性指定默认值

截图来自<python编程:从入门到实践>

我的代码如下:

class Restaurant():
    def __init__(self,restaurant_name,cuisine_type):
        
        self.restaurant_name=restaurant_name
        slef.cuisine_type=cuisine_type
        self.number_served=0
    
    def describe_restaurant(self):
        print(self.restaurant_name.title() + 'is wonderful! And ' + self.cuisine_type.title + 'is the main feature.')
    
    def open_restaurant(self):
        print(self.restaurant_name.title() + 'now is opening! Welcom!')
    
    def people_sercerd(self):
        print('There were ' + str(self.number_served) + ' people have been serverd in ' + self.restaurant_name.title() + '.')
    
    def increment_number_served(self,people_count):
        self.number_served=people_count
        


restaurant=Restaurant("La Blue","kali")
restaurant.describe_restaurant()
restaurant.open_restaurant()
restaurant.people_sercerd()
restaurant.increment_number_served(55)
restaurant.people_sercerd()

相关文章:

  • 2022-03-08
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-23
  • 2021-10-30
猜你喜欢
  • 2022-12-23
  • 2021-10-30
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
相关资源
相似解决方案