我正在尝试创建一个项目,但我遇到了错误。
这是我的代码(不是全部,它很长,但我遇到的问题):
class Rest(object):
def __init__(self, name, order=[], total=0):
self.name = name
self.order = []
self.total = 0
def end_order(self):
print("Here is your complete order: {0}".format(self.order))
print("Here is your total: {0}".format(self.total))
def order_menu(self):
loop = 1
while (loop == 1):
question_1 = raw_input("What would you like? Push S to Submit, Push C to Cancel")
if (question_1 == "1"):
self.total += 4.99
print("You added a cheeseburger, $4.99)
elif (question_1 == "S"):
end_order()
好的,所以在order_menu(self)下,在elif语句下,它给了我一个错误: “未定义全局名称'end_order()'”。
我可能不会做一些愚蠢的事,但我无法弄清楚是什么......
答案 0 :(得分:0)
我相信在调用类方法时,Python中需要self
关键字。尝试:
self.end_order()