In: Computer Science
Create a python program that contains a while loop together with a Sentinel (0) to process indefinite item costs that are purchased online from a vendor. Be sure that you assign a variable SENTINEL to 0 to use in the Boolean condition of your while loop. A sales tax rate of 6.25% is applied to the subtotal for the items purchased. Be sure you assign a variable, TAXRATE to 0.0625.
The program is to process a number of items, numItems, of item costs, itemCost, purchased online to keep track of an indefinite number of items, numItems, purchased and a running subtotal, subTotal, of item costs, itemCost, purchased (entered by the user) until the user enters the sentinel value of 0 for itemCost to stop the processing. The itemCost is read from the keyboard as a floating point value. It is important that you initialize to zero both numItems and subTotal.
Outside of the while loop if the counter, numItems, is not zero, (1) determine the sales tax, salesTax, by multiplying the subTotal by the TAXRATE, (2) determine the total cost after tax, total, by assigning it to the addition of the salesTax to the subTotal, and finally (3) display at the screen the number of items purchased, the sub total, sales tax, and total of the purchase. All monetary values are to be formatted with commas and with two digits to the right of the decimal point. If no items (i.e. numItems is zero) were purchased, then your program is to send to the display an appropriate message such as: "Return when you have purchased items!".)
Given below is the code for the question. PLEASE MAKE SURE
INDENTATION IS EXACTLY AS SHOWN IN IMAGE.
Please do rate the answer if it helped. Thank you.
numItems = 0
subTotal = 0
SENTINEL = 0
TAXRATE = 0.0625
itemCost = -1
while itemCost != SENTINEL:
itemCost = float(input('Enter item cost (type 0 when
done): '))
if itemCost != SENTINEL:
numItems += 1
subTotal += itemCost
if numItems > 0:
salesTax = TAXRATE * subTotal
total = subTotal + salesTax
print('No. of items = ', numItems)
print('Sub Total = {0:,.2f}'.format(subTotal))
print('Sales Tax = {0:,.2f}'.format(salesTax))
print('Total = {0:,.2f}'.format(total))
else:
print('Return when you have purchased items!')