Advertisement
gruntfutuk

grocery

Jun 16th, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. grocery_history = []
  2.  
  3. stop = 'go'
  4. while stop != 'q':
  5.     grocery_item = {}    
  6.     item_name = input ("Item name:\n")
  7.     quantity = input ("Quantity purchased:\n")
  8.     cost = input ("Price per item:\n")  
  9.     grocery_item['name'] = item_name
  10.     grocery_item['number'] = int(quantity)
  11.     grocery_item['price'] = float(cost)
  12.     grocery_history.append(grocery_item)
  13.    
  14.     stop=input("Would you like to enter another item?\nType" + \
  15.                "'c' for continue or 'q' to quit:\n")
  16.  
  17. grand_total=0
  18. for element in grocery_history:
  19.   item_total = element['number'] * element['price']
  20.   grand_total += item_total
  21.   #Output the information for the grocery item to match this example:
  22.   #2 apple  @   $1.49   ea  $2.98
  23.   print(f"{element['number']:>3} {element['name']:>10}\t" + \
  24.         f"@\t${element['price']:>6.2f}\tea\t${item_total}")
  25.  
  26. print(f'Grand total: ${grand_total}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement