2015-05-12 230 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())) –