In: Computer Science
A company sells a product for a retail price of $100. It offers quantity discounts based on the table below
Quantity | Discount |
10-19 |
10% |
20-49 | 20% |
50-99 | 30% |
100 or more | 40% |
Write a program that asks user for enter the quantity of product they want to purchase. It should then display the discount amount (if any) and the total purchase amount after the discount. The output should be displayed with 2 decimal points as shown below.
See a sample output
Enter the quantity of the product you want to purchase: 30
Discount Amount: $ 600.00
Total Purchase Amount: $ 2400.00
Refer the rubric and coding standards documents. Make sure you submit by 11:59 pm of the due date. Make sure you write the analysis/design algorithm along with properly documented code. Do not forget to attach your SDM as either another document or as a submission text when you submit your homework
Source Code:
Output:
Code in text format (See above images of code for indentation):
#read quantity from user
quantity=int(input("Enter the quantity of the product you want to
purchase: "))
#variables
discount=0
amount=0
#check for 10-19 and assign discount
if(quantity>=10 and quantity<20):
discount=0.10
#check for 20-49 and assign discount
elif(quantity>=20 and quantity<50):
discount=0.20
#check for 50-99 and assign discount
elif(quantity>=50 and quantity<100):
discount=0.30
#check for 100 or more and assign discount
elif(quantity>=100):
discount=0.40
#calculate discount amount
discount=discount*quantity*100
#calculate amount
amount=quantity*100-discount
#print discount and total amount
print("Discount Amount: $",round(discount,2))
print("Total Purchase Amount: $",round(amount,2))
'''
***********Algorithm******************
START
Read quantity from user
initialize discount and amount variables to 0
if quantity between 10-19 assign discount of 10% (0.1)
else if quantity between 20-49 assign discount of 20% (0.2)
else if quantity between 50-99 assign discount of 30% (0.3)
else if quantity 100 or more assign discount of 40% (0.4)
calculate discount as discount*quantity*100
calculate amount as quantity*100-discount
print discount and total amount and using round method print upto 2
decimal
END
******************************************
'''