In: Computer Science
Python: Write a program to simulate the purchases in a grocery store. A customer may buy any number of items. So, you should use a while loop. Your program should read an item first and then read the price until you enter a terminal value (‘done’) to end the loop. You should add all the prices inside the loop. Add then a sales tax of 8.75% to the total price. Print a receipt to indicate all the details of the purchase. All numbers must be appropriately formatted. For example, when the program starts, it shall prompt user to enter line item, say “enter an item or end the program by entering ‘done’ >> “. After user enters the item, say “book”, the program shall prompt user enter price, say “please enter the price you pay, without dollar sign, just a number >> ‘. Then the program repeats the process until user prompts ‘done’. Students may get partial credits if they draw problem solving strategy and pseudo-code when they could not get their program run successfully. When the program run successfully, there is no need to do that.
(Below is the code in python which takes items and then its price and displays the receipt:) ---
str=input("enter an item or end the program by entering 'done' >> ")
book_list=[]
price_list=[]
total=0
while str!='done':
book_list.append(str)
price=float(input("please enter the price you pay, without dollar sign, just a number >> "))
price_list.append(price)
total +=price;
str=input("enter an item or end the program by entering 'done' >> ")
print("\nReceipt:")
for i in range(0,len(book_list)):
print(i+1,". ",book_list[i]," ",price_list[i])
total_price=(108.75/100)*total
print("\nSales Tax: ",((8.75/100)*total))
print("\nTotal price: ",total_price)
Output sample -1:
Code image :