Advertisement
DiYane

Furniture

Sep 27th, 2023
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import re
  2.  
  3. main_string = input()
  4.  
  5. pattern = re.compile(
  6.     r">>(?P<furniture_name>[A-Za-z]+)<<(?P<price>[0-9]+[\.0-9]*)!(?P<quantity>[0-9]+)")
  7.  
  8. total_money_spend = 0
  9. print("Bought furniture:")
  10. while main_string != "Purchase":
  11.     result = re.finditer(pattern, main_string)
  12.     for show in result:
  13.         total_money_spend += float(show["price"]) * float(show["quantity"])
  14.         print(show["furniture_name"])
  15.     main_string = input()
  16.  
  17. print(f"Total money spend: {total_money_spend:.2f}")
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement