2. (13 Points) Write a program Sales.py that performs the following, A retail st
ID: 3730484 • Letter: 2
Question
2. (13 Points) Write a program Sales.py that performs the following, A retail store sale T-shirts. T-shirt cost $8.99 each. Sales tax is 8.5%. Define a function called totalcost, def totalcost(n), which takes one parameter, the number of T-shirts, calculates and returns the totalcost for purchasing the T- shirts (cost of the shirts with tax applied). Call totalcost function in the program to produce a sales table that shows the total cost as shown in the sample output. (No need to take user input). · . . (3 pts)Enhancement: The store now has a sale, buy 3 and get 1 free. Define another functions, def salescost(n) to calculate the cost with the sales applied. Call the salescost function in the program to show the sales cost. Sample output: (with enhancement) T-shirt unit price: $ 8.99 Tax rate: 8.50% # of T-shirts Original Cost 9.75 $19.51 $29.26 $ 39.02 $ 48.77 $58.52 $ 68.28 78.03 $ 87.79 $97.54 Sales Cost $ 9.75 19.51 $29.26 29.26 $39.02 $48.77 $58.52 $ 58.52 $ 68.28 $ 78.03 4 5 7 10Explanation / Answer
def totalcost(n): #function to calculate total cost
tShirt = 8.99 #cost of each T-shirt
tax = (tShirt * 8.5)/100 #tax for each T-shirt
costOfTShirt = round(tShirt+tax,2) #cost of each T-shirt with tax
return n*costOfTShirt #cost of n T-shirts
def salescost(n): #function to calculate cost of the n T-shirt with offer buy3 and get 1
tShirt = 8.99 #cost of each T-shirt
tax = (tShirt * 8.5)/100 #tax for each T-shirt
costOfTShirt = tShirt+tax #cost of each T-shirt with tax
return n*costOfTShirt - (n//4)*costOfTShirt #as 4 th T-shirt is free for 3 shirts bought
print("# of T-shirts " + " " + " Original Cost" + " " + "Sales Cost ")
for i in range(1,11): #for finding cost of no of T-shirts as in i
print(" " + str(i) + " " + "$" + str(round(totalcost(i),2)) + " " + "$" + str(round(salescost(i),2)))
output:
# of T-shirts Original Cost Sales Cost
1 $9.75 $9.75
2 $19.5 $19.51
3 $29.25 $29.26
4 $39.0 $29.26
5 $48.75 $39.02
6 $58.5 $48.77
7 $68.25 $58.52
8 $78.0 $58.52
9 $87.75 $68.28
10 $97.5 $78.03
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.