Advertisement
GalinaKG

Furniture

Jul 21st, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. import re
  2.  
  3. pattern = r">>(?P<name>[a-zA-Z]+)<<(?P<price>\d+(\.\d+)?)\!(?P<quantity>\d+)"
  4. line = input()
  5. furniture_names = []
  6. total_money = 0
  7.  
  8. while line != 'Purchase':
  9.     match = re.match(pattern, line)
  10.  
  11.     if match:
  12.         data = match.groupdict()
  13.         furniture_names.append(data['name'])
  14.         total_money += int(data['quantity']) * float(data['price'])
  15.  
  16.     line = input()
  17.  
  18. print('Bought furniture:')
  19. if furniture_names:
  20.     print('\n'.join(furniture_names))
  21. print(f'Total money spend: {total_money:.2f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement