In: Computer Science
We are going to include various discount to the online order for the chocolate company.
Remember from Program #2:
The online store sells the following gourmet chocolates:
Now for Program #3, also include the following order discount available:
The store allows a customer discount based on:
Net Subtotal = Gross Subtotal – Discount
Company charges a 10% Shipping and Handling fee and a 9.5% Sales Tax (sales tax rate).
Both Shipping & Handling and Sales Tax is based on Net Subtotal.
Invoice Total is Net Subtotal plus Shipping and Handling plus Sales Tax.
Using a nested IF…ELSE...IF, determine the discount based on the gross subtotal of the order (excluding the shipping and handling.
Sample Output (bold italic in red is user input during execution of the program)
Enter Customer ID: AF101
Number of box of Milk Chocolate @ $8.50: 2
Number of box of Dark European @ $9.75: 1
Number of box of White Chocolate @ $10.50: 3
Number of box of European Truffle @ $12.50: 0
Invoice for Customer AF101:
2 Milk Chocolate @$8.50 per box $ 17.00
1 Dark European @$9.75 per box $ 9.75
3 White Chocolate @$10.50 per box $ 31.50
0 European Truffles @$12.50 per box $ 0.00
Subtotal $ 58.25
Less Discount of 15.0 % $ 8.74
Net Subtotal $ 49.51
Shipping @ 10.0 % $ 4.95
Sales Tax @ 9.5% $ 4.70
Grand Total $ 59.16
Answer :
Here is the python code as per your requiremet
Raw code:
#ASKING INPUTs from user
id=input('Enter Customer ID: ')
milkChoclates=int(input('Number of box of Milk Chocolate @ $8.50: '))
darkEuroChoclates=int(input('Number of box of Dark European @ $9.75: '))
whiteChoclate=int(input('Number of box of White Chocolate @ $10.50: '))
euroTruffle=int(input('Number of box of European Truffle @ $12.50: '))
#calculating cost of each by multiplying the number of quantity
milkChoclatesCost=8.50*milkChoclates
darkEuroChoclatesCost=9.75*darkEuroChoclates
whiteChoclateCost=10.50*whiteChoclate
euroTruffleCost=12.50*euroTruffle
#total
subTotal=milkChoclatesCost+darkEuroChoclatesCost+whiteChoclateCost+euroTruffleCost
#condtions to decide discount percentage
if subTotal<20.00:
discount=0
elif subTotal>=20.00 and subTotal<=39.99:
discount=10
elif subTotal>=40.00 and subTotal<=59.99:
discount=15
elif subTotal>=60.00 and subTotal<=79.99:
discount=20
elif subTotal>=80:
discount=25
#get the discount price
discountPrice=(discount/100)*subTotal
#subtract discount price from total price
netSubtotal=subTotal-discountPrice
#shipping cost 10%
shippingCost=(10/100*netSubtotal)
# sales tax 9.5%
salesTax=(9.5/100*netSubtotal)
#total taxes
taxes=shippingCost+salesTax
#grand total
grandTotal=(netSubtotal+taxes)
#print statements
invoice='''
Invoice for Customer {}:
{} Milk Chocolate @$8.50 per box $ {:.2f}
{} Dark European @$9.75 per box $ {:.2f}
{} White Chocolate @$10.50 per box $ {:.2f}
{} European Truffles @$12.50 per box $ {:.2f}
Subtotal $ {:.2f}
Less Discount of {:.2f} % $ {:.2f}
Net Subtotal $ {:.2f}
Shipping @ 10.0 % $ {:.2f}
Sales Tax @ 9.5% $ {:.2f}
Grand Total $ {:.2f}
'''.format(id,milkChoclates,milkChoclatesCost,darkEuroChoclates,darkEuroChoclatesCost,whiteChoclate,whiteChoclateCost,euroTruffle,euroTruffleCost,subTotal,discount,discountPrice,netSubtotal,shippingCost,salesTax,grandTotal)
#printing invoice
print(invoice)
Editor:
Hope this helps you! If you still have any doubts or queries please feel free to comment in the comment section.
"Please refer to the screenshot of the code to understand the indentation of the code".
Thank you! Do upvote.