Advertisement
go6odn28

5. Furniture

Mar 15th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import re
  2.  
  3. total_price = 0
  4. furniture_list = []
  5.  
  6. while True:
  7.     text = input()
  8.     if text == 'Purchase':
  9.         break
  10.  
  11.     pattern = r">>(?P<furniture>[A-Za-z]+)<<(?P<price>\d+(\.\d+)?)!(?P<quantity>\d+)\b"
  12.     matches = re.finditer(pattern, text)
  13.  
  14.     for match in matches:
  15.         furniture_name = match.group("furniture")
  16.         price = float(match.group("price"))
  17.         quantity = int(match.group("quantity"))
  18.  
  19.         total_price += price * quantity
  20.         furniture_list.append(furniture_name)
  21.  
  22. print("Bought furniture:")
  23. for furniture in furniture_list:
  24.     print(f"{furniture}")
  25. print(f"Total money spend: {total_price:.2f}")
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement