Advertisement
viligen

furniture

Nov 20th, 2021
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import re
  2.  
  3. pattern = r">>([a-zA-Z]+)<<(\d+\.?\d*)!(\d+)\b"
  4. bought_furniture = []
  5. total_sum = 0
  6. while True:
  7.     line = input()
  8.     if line == "Purchase":
  9.         break
  10.     match = re.search(pattern, line)
  11.     if match:
  12.         product, price, quantity = match.groups()
  13.         bought_furniture.append(product)
  14.         total_sum += float(price) * int(quantity)
  15.  
  16. print("Bought furniture:")
  17. for each in bought_furniture:
  18.     print(each)
  19. print(f"Total money spend: {total_sum:.2f}")
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement