Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

csci1040-Test2- (auto-E : 2) - Jup x X C hub.science.ontariotechu.ca/user/100820459/lab/workspaces/auto-E/tree/csci 1040-Test2-Dec6.ipynb File Edit View Run Kernel Tabs Settings Help Launcher X CSCI1040U - Assignment2-Fix _

image text in transcribedimage text in transcribed
csci1040-Test2- (auto-E : 2) - Jup x X C hub.science.ontariotechu.ca/user/100820459/lab/workspaces/auto-E/tree/csci 1040-Test2-Dec6.ipynb File Edit View Run Kernel Tabs Settings Help Launcher X CSCI1040U - Assignment2-Fix _ csci1040-Test2-Dec6.ipynb X a+K 0 0 c Markdown v Python 3 (ipykernel) O # O O SUPER DEALS An online store allows customers to apply coupons on checkout. Currently, the store has a few coupons valid: DEAL10 : gives 20% off on purchases of 20$ or more. . DEAL 100 : 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 a 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, than return (-1, -1) instead. [2]: # Your solution def validateCoupon (coupon) : coupons = ["DEAL10", "DEAL100", "XMASFREE", "ALL10"] tup = [[rate], [min]] if coupon in coupons: if coupon == "DEAL10" : rate . append (0. 2) min . append(1.0) else: rate . append ( -1) min . append( -1) 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 . prints: Simple O s_ 0 @ Python 3 (ipykernel) | Idle Saving completed Mode: Command & Ln 1, Col 1 csci1040-Test2-Dec6.ipynb 6:46 PM Type here to search 0.C Mostly cloudy ~ 9 4 7 ()) ENG 2021-12-06csci1040-Test2- (auto-E : 2) - Jup x X C A hub.science.ontariotechu.ca/user/100820459/lab/workspaces/auto-E/tree/csci 1040-Test2-Dec6.ipynb File Edit View Run Kernel Tabs Settings Help Launcher X CSCI1040U - Assignment2-Fix _ csci1040-Test2-Dec6.ipynb X a+X 0 0 > c > Markdown Python 3 (ipykernel) O O O 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 . prints: " a total amount of the purchase after calculate 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 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 ". [4]: # Your solution def validateCoupon( coupon) : coupons = ["DEAL10", "DEAL100", "XMASFREE", "ALL10"] tup = [[rate], [min]] if coupon in coupons: if coupon == "DEAL10": rate . append (0.2) min . append(1.0) else: rate . append( -1) min . append (-1) # # test cases - uncomment and run before submiting applyCoupon( "DEAL10", 150) #outputs Coupon Applied. Your total is 120 # applyCoupon( "DEAL1000", 78.59) #outputs Coupon could not be applied. Your total is 78.59 # applyCoupon( "DEAL100", 85.63) #outputs Coupon could not be applied. Your total is 85.63 # applyCoupon( "XMASFREE", 113.45) #outputs Coupon Applied. Your total is 96.43 # applyCoupon( "ALL10", 75.0) #outputs Coupon Applied. Your total is 67.50 NameError Traceback (most recent call last) /tmp/ipykernel_204/3202581029.py in 13 # - -- 14 # test cases - uncomment and run before submiting ---> 15 applyCoupon("DEAL10", 150) #outputs Coupon Applied. Your total is 120 16 # applyCoupon( "DEAL1000", 78.59) #outputs Coupon could not be applied. Your total is 78.59 17 # applyCoupon("DEAL100", 85.63) #outputs Coupon could not be applied. Your total is 85.63 NameError: name ' applyCoupon' is not defined Simple O 0 s_ 0 @ Python 3 (ipykernel) | Idle Saving completed Mode: Command & Ln 1, Col 1 csci1040-Test2-Dec6.ipynb Type here to search 6:46 PM 0.C Mostly cloudy ~ 9 4 7 () ENG 2021-12-06

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Have code please and explain

Answered: 1 week ago