In: Computer Science
PYTHON
Part A. Write a program for salespersons to show discounted prices.
a) Request the salesperson to enter the listed price of a
product
b) Write a function to meet the requirements:
i. The function takes the listed price as a parameter
ii. Print a table which lists discounted prices (10%, 20%, 30%,
40%, and 50% off) (see below)
iii. Note that the printing job needs to be done inside the
function [3 pts]
Part B. Write another program to meet additional
requirements:
c) Request the salesperson to enter 2 inputs: (1) the listed price
& (2) increment of discount rates.
For example: the salesperson can enter 0.05 to indicate a 5%
discount increment.
d) Write a function to meet the requirements:
i. The function takes two parameters: (1) the listed price &
(2) the rate increment
ii. Using a loop, print a table which lists discounted prices, up
to 50% off (see below)
iii. Note that the printing job needs to be done inside the
function
Note: All prices (including listed & discounted) must be presented with 2 decimals and $. For discount rate increment, the smallest possible input is 0.01, i.e., 1%. No need to worry if a rate incremental has 3 decimals or more.
PART-A
#function to print the discount rates
def printDiscounts(Listed_Price):
print("Listed Price : $",Listed_Price);#print the listed
Price
#print the price after 10% discount
print("After 10% discount Price : $","{0:.2f}".format(Listed_Price
- (Listed_Price*0.1)))
#print the price after 20% discount
print("After 20% discount Price : $","{0:.2f}".format(Listed_Price
- (Listed_Price*0.2)))
#print the price after 30% discount
print("After 30% discount Price : $","{0:.2f}".format(Listed_Price
- (Listed_Price*0.3)))
#print the price after 40% discount
print("After 40% discount Price : $","{0:.2f}".format(Listed_Price
- (Listed_Price*0.4)))
#print the price after 50% discount
print("After 50% discount Price : $","{0:.2f}".format(Listed_Price
- (Listed_Price*0.5)))
#read the listed price from user
Listed_Price = (float)(input("Enter the Listed Price of Product :
"))
#call to printDiscounts()
printDiscounts(Listed_Price)
output
PART-B
#function to print the discount rates
def printDiscounts(Listed_Price,IncDiscount):
print("Listed Price : $",Listed_Price);#print the listed
Price
#loop to print the incremented discounted amount
for i in range(1,6):
j= (i*10)/100 +IncDiscount;
#print the price after 10% discount
print("After ",(int)(j*100),"% discount Price :
$","{0:.2f}".format(Listed_Price - (Listed_Price*j)))
#read the listed price from user
Listed_Price = (float)(input("Enter the Listed Price of Product :
"))
#READ THE incremented discount
IncDiscount = (float)(input("Enter the incremented discount :
"))
#call to printDiscounts()
printDiscounts(Listed_Price,IncDiscount)
output