In: Computer Science
You are off to shopping and need a program that allows you to enter the names of items, their price and quantities. Here is what a sample run should look like (with the keyboard input shown in italics) ...
Enter item information ("exit" to exit) item 1: chips price: 3.5 quantity: 2 Enter item information ("exit" to exit) item 2: red wine price : 15.0 quantity : 1 Enter item information ("exit" to exit) item 3 : steaks price : 15.0 quantity : 2 Your list: steaks 2 $30 red wine 1 $15 chips 2 $7 ----------------------------- Total $52
You must use PYTHON.
Code
import operator
i=1
l=[]
while(True):
print('Enter item information ("exit" to exit)')
m=[]
print("item",str(i)+':',end=' ')
item=input()
if(item=='exit'):
break
print('price :',end='')
price=float(input())
print('quantity: ',end='')
quantity=int(input())
m.append(item)
m.append(quantity)
tot_price=int(quantity*price)
m.append(tot_price)
l.append(m)
i=i+1
n=sorted(l, key=operator.itemgetter(2))
print()
print('Your list:')
total=0
for i in n:
print(i[0],' ',i[1],' $'+str(i[2]))
total+=i[2]
for i in range(29):
print('_',end='')
print()
print('Total \t',' $'+str(total))
Terminal Work
.