codio grocery list python

Solutions on MaxInterview for codio grocery list python by the best coders in the world

showing results for - "codio grocery list python"
Joshua
30 Sep 2018
1# codio grocery list python
2grocery_item = {} 
3grocery_history = [] 
4
5stop = False 
6
7while not stop:
8    item_name = input("Item name:\n")   
9    quantity = input("Quantity purchased:\n")   
10    cost = input("Price per item:\n")
11    grocery_item = {'name':item_name, 'number': int(quantity), 'price': float(cost)}
12    grocery_history.append(grocery_item)
13    user_input = input("Would you like to enter another item?\nType 'c' for continue or 'q' to quit:\n")
14    if user_input == 'q':
15      stop = True
16    
17grand_total = 0  
18
19for index, item in enumerate(grocery_history):
20    item_total = item['number'] * item['price']
21    grand_total = grand_total + item_total
22    print('%d %s @ $%.2f ea $%.2f' % (item['number'], item['name'], item['price'], item_total))
23    item_total = 0
24
25print('Grand total: $%.2f' % grand_total)