Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
coupon
# change 50 to the price of your cart price = 137.68 from random import randint # to update with new coupons search codes on community wiki # in the below list all X off Y+ purchases with their 4 digit codes # (x, y) refers to an $X off $Y+ purchase # (x, 0) refers to a x% off entire pruchase CODES = { (10, 50) : "0972" ,(20, 100) : "1134" ,(10, 0): "0620" } # define coupons def applycoupon(i, j, price): """apply coupons""" price = 1.0*price if (i, j) in CODES: if j==0: return (1-(i/100.0))*price, CODES[(i, j)] elif price >= j: return price - i, CODES[(i, j)] else: return price, CODES[(i, j)] else: return price, "code not in dict" def min_price_w_coupon(cartprice): """check the best coupon to apply to a cart""" p_w_coupon = cartprice code = "no applicable coupon" for key in CODES: i = key[0] j = key[1] test_coup = applycoupon(i, j, cartprice) test_coup_price = test_coup[0] test_coup_code = test_coup[1] if test_coup_price < p_w_coupon: p_w_coupon = test_coup_price code = test_coup_code return p_w_coupon, code def addcheckdigit(stuff): checkdigit = 0 for j in range(14): if j % 2 == 0: checkdigit += int(stuff[j]) else: checkdigit += int(stuff[j]) * 3 print(str(stuff) ) + str((10 -(checkdigit % 10))%10) def coupon_generator(price): if min_price_w_coupon(price)[1] == "no applicable coupon" or min_price_w_coupon(price)[1] == "code not in dict": print("no applicable coupon") else: for j in range(100): i = randint(0, 50000) addcheckdigit("47000" + "%05d" % i + min_price_w_coupon(price)[1]) coupon_generator(price)
run
|
edit
|
history
|
help
0
PyClaMInher
Prime number finder and counter in range (ex: 0-100) using python
RandomShape
Speed up Python2 nested loops with XOR
codeacademy python tasks
runologist
Dictionary comprehension - convert to lowercase
Fold an array
Shabnam_name_checker
PythonTuple