2015-11-04 110 views
-3

我有這段代碼在這裏,我想知道爲什麼我得到「total_with_tax未定義」未定義功能混亂

發生這種情況時,我做的:

c = Customer() 
c.print_bill() --> this is where I get the error 

代碼:

class Customer: 
def __init__(self): 
    self.total = 0 
    self.items_ordered = str("") 

def add_to_order(self, NameOfItem, CostOfItem): 
    self.total += CostOfItem 
    self.items_ordered = self.items_ordered + (str(NameOfItem) + ", ") 

def total_with_tax(self): 
    return ((self.total * 0.13) + self.total) 

def print_bill(self): 
    print("----------------------------------------------") 
    print(self.items_ordered) 
    print("$%d" %(self.total)) 
    print("$%d" %(total_with_tax())) 
    print("----------------------------------------------") 
+1

您的縮進全部關閉。這在Python中很重要。 – juanchopanza

回答

2

您需要將total_with_tax加上self,如下所示:

print("$%d" % self.total_with_tax()) 
+0

謝謝!幫助了很多 – katie1245