python - Discount function not working -


#function - discount buy 5 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) 

i can't discount function work, it's python 3.4 using tkinter.

this function should give discount, if customer bought 5 donuts 1 free.

this how compute what believe you're after:

example:

def discount(p, n, f=0):     """calculate discount percentage (given 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) 

demo:

>>> 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 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -