Advertisement
Guest User

Untitled

a guest
Feb 13th, 2022
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import re
  2.  
  3. pattern = re.compile("^>>([A-Za-z]+)<<([0-9]+\.?[0-9]*)!([0-9]+)$")
  4. text = input()
  5. all_furniture = {}
  6.  
  7. while text != "Purchase":
  8. if pattern.match(text):
  9. matches = pattern.finditer(text)
  10. for match in matches:
  11. furniture = match.group(1)
  12. price = float(match.group(2))
  13. quantity = int(match.group(3))
  14. if furniture not in all_furniture:
  15. all_furniture[furniture] = []
  16. all_furniture[furniture].append(price)
  17. all_furniture[furniture].append(quantity)
  18. else:
  19. all_furniture[furniture][0] = price
  20. all_furniture[furniture][1] += quantity
  21. text = input()
  22.  
  23. print("Bought furniture:")
  24. total_sum = 0
  25. for key, value in all_furniture.items():
  26. print(f"{key}")
  27. total_sum += value[0] * value[1]
  28. print(f"Total money spend: {total_sum:.2f}")
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement