Advertisement
simeonshopov

5. Furniture

Feb 24th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import re
  2.  
  3. to_purchase = []
  4. total_sum = 0
  5.  
  6. while True:
  7.     command = input()
  8.     if command == 'Purchase':
  9.         break
  10.     search = r'((>>)(?P<item>[a-zA-Z]+)(<<)(?P<price>[0-9]+([.0-9]+)?)!(?P<quantity>[0-9]+))'
  11.     match = re.search(search, command)
  12.     if match is not None:
  13.         item = match.group('item')
  14.         price = match.group('price')
  15.         quantity = match.group('quantity')
  16.         to_purchase.append((item, price, quantity))
  17.  
  18. for x in to_purchase:
  19.     total_sum += float(x[1]) * int(x[2])
  20.  
  21. print('Bought furniture:')
  22. [print(x[0]) for x in to_purchase]
  23. print(f'Total money spend: {total_sum:.2f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement