Guest User

Untitled

a guest
Nov 14th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. prices = {}
  2. groceries = []
  3.  
  4. file = open("grocery_store_price_list.txt", "r")
  5. for strx in file:
  6. strs = list(filter(None, strx.strip().split(" ")))
  7. prices[strs[0]] = [strs[1]], [strs[2]]
  8. file.close()
  9.  
  10. file = open("my_personal_gro_list.txt", "r")
  11. for strx in file :
  12. strs = list(filter(None, strx.strip().split(" ")))
  13. groceries.append([strs[1], strs[0]])
  14.  
  15. headings = "{:15s} {:3s} {:10s} {:5s} {:6s}".format("item", "qty", "unit",
  16. "cost", "total")
  17.  
  18. print(headings)
  19.  
  20. finalCost = 0
  21.  
  22.  
  23. for strs in groceries:
  24. item = strs[0]
  25. qty = int(strs[1])
  26. unit = prices[strs[0]][1]
  27. cost = float(prices[strs[0]][0][0])
  28. total = qty*cost
  29.  
  30. finalCost += total
  31.  
  32. print(item, qty, unit, cost, total,)
Add Comment
Please, Sign In to add comment