NameError: name xxxxxx is not defined

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的单引号忘记加了!!!!!啊啊啊啊

转载于:https://www.cnblogs.com/yfsm1123/p/10713446.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值