2015-05-12 225 views
0
#Function - Discount for Buy 5 get 1 Free 
def Generate_Discount1(): 
     if (entWindow1.get() != ""): 
       price = 0.99 
       free = 1 
       DiscNo = (int(entWindow1.get())+ 
          int(entWindow2.get())+ 
          int(entWindow3.get())+ 
          int(entWindow4.get())+ 
          int(entWindow5.get())+ 
          int(entWindow6.get())+ 
          int(entWindow7.get())+ 
          int(entWindow8.get())+ 
          int(entWindow9.get())) 
       total_bought = float (price*DiscNo) 
       total_free = float (price*free) 
       return 0.2/(total_bought/total_free) 

我無法讓我的折扣功能正常工作,它是使用tkinter的python 3.4。折扣功能不能正常工作

此功能應該給予折扣,如果客戶購買了5個甜甜圈,他們將獲得一個免費。

+1

你是什麼意思與「不起作用「?你有錯誤信息嗎?你會得到意想不到的行爲?此外,您應該嘗試製作[MCVE](http://stackoverflow.com/help/mcve),您發佈的代碼不能由任何人運行和調試。我們必須猜測'totalT','stvDicountOne'等是如何定義的。 – fhdrsdg

+0

示例代碼甚至不是有效的Python(*不完全*)。 - 我確定在'''.get''和''set''周圍缺少一些東西。只是不知道什麼:) –

+1

應該'標籤(...)'是'標籤(...)'?另外,「set」和「get」應該是什麼意思? –

回答

1

這是你如何計算什麼,我相信你是後:

例子:

def discount(p, n, f=0): 
    """Calculate discount as a percentage (given as a float) 
     given: 

     (p)rice 
     (n)umber 
     (f)ree 
    """ 

    total_bought = float(p * n) 
    total_free = float(p * f) 

    return 1.0/(total_bought/total_free) 

演示:

>>> discount(1, 5, 1) 
0.2 # 20% discount 
>>> discount(1, 5, 2) 
0.4 # 40% discount 
>>> discount(1, 6, 3) 
0.5 # 50% discount 
>>> discount(1, 6, 6) 
1.0 # 100% discount 
+0

我會在哪裏輸入代碼在我的編碼? –

+0

謝謝,但我會在哪裏輸入該編碼在我的? –

+0

#功能 - 購買折扣9獲得3免費 def Generate_Discount2(): if(entWindow1.get()!=「」): discTwo = 3 // 9-(int(entWindow1.get())+ int(entWindow2.get())+ int(entWindow3.get())+ int(entWindow4.get())+ int(entWindow5.get())+ int(entWindow6.get())+ int(entWindow7.get())+ int(entWindow8.get())+ int(entWindow9.get())) –