Question
An online store allows customers to apply coupons at checkout. Currently, the store has a few coupons valid: DEAL10: gives 20% off on purchases of
An online store allows customers to apply coupons at checkout. Currently, the store has a few coupons valid:
DEAL10: gives 20% off on purchases of 20$ or more.
DEAL100: gives 35% off on purchases of 100$ or more.
XMASFREE: gives 15% off on purchases of 50$ or more.
ALL10: gives 10% off on purchases without minimum spending.
Part 1
Write a function validateCoupon that receives a coupon and returns the discount percentage (i.e. 0.2 for 20% off) and the minimum amount to apply the discount.
This function will:
Receive coupon argument: string name of the coupon
Return a tuple rate, min with the discount percentage and the minimum purchase, respectively. - If the coupon is not among the list of valid coupons then return (-1,-1) instead.
Part 2
Write a function applyCoupon which calls the function validateCoupon from part 1.
This function will:
Receive a cpn string argument with the name of the coupon
Receive a checkout numeric argument with the amount of the purchased 1
prints:
- a total amount of the purchase after calculating the price with the coupon if the coupon is valid and they have spent the minimum amount, along with the message "Coupon Applied. Your total is total".
- prints a total amount of the purchase which is the same as the checkout amount if the coupon is invalid or they did not spend the minimum amount, along with the message "Coupon could not be applied. Your total is total"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started