折扣功能不起作用

时间:2015-05-12 09:11:18

标签: python python-3.x tkinter

%b is for Boolean
%f is for Decimal floating-point
%c is for Character
%d is for Decimal integer
%s is for String

我无法使用折扣功能工作,使用tkinter进行python 3.4。

这个功能应该给予折扣,如果顾客买了5个甜甜圈,他们会免费获得一个。

1 个答案:

答案 0 :(得分: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