Advertisement
go6odn28

5_furniture_

Mar 18th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. import re
  2. furniture_list = []
  3. pattern = r"(?P<Furniture>[A-Za-z]+)<<(?P<Price>\d+[\.\d+]*)!(?P<Quantity>\d+)"
  4. total_sum = 0
  5. while True:
  6.     command = input()
  7.     if command == "Purchase":
  8.         print("Bought furniture:")
  9.         if furniture_list:
  10.             print('\n'.join(furniture_list))
  11.         break
  12.     matches = re.search(pattern, command)
  13.     if matches:
  14.         some_dict = matches.groupdict()
  15.         furniture_list.append(some_dict["Furniture"])
  16.         total_sum += float(some_dict["Price"]) * int(some_dict["Quantity"])
  17.  
  18. print(f"Total money spend: {total_sum:.2f}")
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement