Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- prices = {}
- groceries = []
- file = open("grocery_store_price_list.txt", "r")
- for strx in file:
- strs = list(filter(None, strx.strip().split(" ")))
- prices[strs[0]] = [strs[1]], [strs[2]]
- file.close()
- file = open("my_personal_gro_list.txt", "r")
- for strx in file :
- strs = list(filter(None, strx.strip().split(" ")))
- groceries.append([strs[1], strs[0]])
- headings = "{:15s} {:3s} {:10s} {:5s} {:6s}".format("item", "qty", "unit",
- "cost", "total")
- print(headings)
- finalCost = 0
- for strs in groceries:
- item = strs[0]
- qty = int(strs[1])
- unit = prices[strs[0]][1]
- cost = float(prices[strs[0]][0][0])
- total = qty*cost
- finalCost += total
- print(item, qty, unit, cost, total,)
Add Comment
Please, Sign In to add comment