我不斷收到這樣的錯誤。這是一個餐廳代碼,其中菜單打印和訂單被採取,但錯誤是在寫入文件中的訂單和成本文本,修復thsi請
我試圖做一個字典形式的菜單,但不能寫文本文件
class restaurant():
def __init__(self):
self.name = ""
self.menu = {}
self.order = []
self.bill = 0
def print_menu(self):
print "MENU CARD"
self.menu = {'BBQ Grill':'50','Chicken Gollati':'80','French fries':'60',
'Hara Bara Kabab':'90','Makani Special Dum Biriyani':'100',
'Egg Jumbo Sandwich':'120','Roasted Prawn Salad':'90',
'Parathas':'80','Turkish Barbeque Plate':'100'}
for item in self.menu:
print item,"-",self.menu[item]
def takeorder(self):
f1 = open("billlog.txt","w")
print "What would you like to order?"
ans = "y"
while ans == "y":
food = raw_input("enter order - ")
self.bill += int(self.menu[food])
ans = raw_input("go on?(y/n): ")
f1.write(food)
f1.write("\t\t")
f1.write(self.bill)
print food,"\t\t\t",self.bill
f1.close()
def readfilebilllogs(self):
f1 = open("billlog.txt","r")
f1.read()
f1.close()
r = restaurant()
r.print_menu()
r.takeorder()
r.readfilebilllogs()
當出現錯誤時,代碼是不正確的。錯誤也很明顯:你在分配一個值之前引用了一個變量。你可能想'self.bill' ... –
請將錯誤信息添加爲文本,而不是圖像。 – Matthias