Advertisement
Guest User

Untitled

a guest
Jan 11th, 2022
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. import re
  2.  
  3. pattern = r">>(?P<name>[A-Za-z]+)<<(?P<price>\d+\.?\d*)!(?P<quantity>\d+)"
  4. text = input()
  5. total = 0
  6. furniture_name = []
  7. while not text == 'Purchase':
  8.  
  9.     match = re.findall(pattern, text)
  10.     if match:
  11.         for i in match:
  12.             furniture_name.append(i[0])
  13.  
  14.             price = float(i[1])
  15.             quantity = float(i[2])
  16.             total += price * quantity
  17.  
  18.     text = input()
  19. print('Bought furniture:')
  20. for i in furniture_name:
  21.     print(i)
  22. print(f'Total money spend: ' + "{:.2f}".format(total))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement