python编程,从入门到实践 9_6 错题
Traceback (most recent call last):
File "9_6.py", line 46, in <module>
my_flavors =IceCreamStand('Hoagen Dazs' , 'ice-cream')
File "9_6.py", line 40, in __init__
self.flavors = orange
NameError: name 'orange' is not defined
1 # # coding=GBK 2 class Restaurant(): 3 """餐厅的描述""" 4 def __init__ (self , restaurant_name , cuisine_type): 5 """初始化属性值restaurant_name和cuisine_type""" 6 self.restaurant_name = restaurant_name 7 self.cuisine_type = cuisine_type 8 self.number_served = 0 9 10 def describe_restaurant(self): 11 """描述餐厅""" 12 print(self.restaurant_name.title() + " is very good.") 13 print("My restaurant is good at " + self.cuisine_type + " .") 14 15 def open_restaurant(self): 16 """开放中的餐厅""" 17 print(self.restaurant_name.title() + " is opening!") 18 19 def restaurant_number(self): 20 """打印到餐厅用餐的人数""" 21 print("There are " + str(self.number_served) + " people!") 22 23 def change_number(self , person): 24 """修改餐厅人数""" 25 self.number_served = person 26 27 def increment_number_served(self , person): 28 """将人数进行递增""" 29 self.number_served += person 30 31 class IceCreamStand(Restaurant): 32 """一家冰激凌店""" 33 34 def __init__ (self , restaurant_name , cuisine_type): 35 """ 36 初始化餐厅的属性 37 初始化冰激凌店的属性 38 """ 39 super(). __init__ (restaurant_name , cuisine_type) 40 self.flavors = orange 41 42 def flavors_food(self): 43 """打印一条喜欢冰激凌口味的消息""" 44 print("I like " + self.flavors + "'s ice-cream.") 45 46 my_flavors =IceCreamStand('Hoagen Dazs' , 'ice-cream') 47 print(my_flavors.describe_restaurant()) 48 my_flavors.flavors_food()
发现是第40行内的orange的单引号忘记加了!!!!!啊啊啊啊