Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- to_purchase = []
- total_sum = 0
- while True:
- command = input()
- if command == 'Purchase':
- break
- search = r'((>>)(?P<item>[a-zA-Z]+)(<<)(?P<price>[0-9]+([.0-9]+)?)!(?P<quantity>[0-9]+))'
- match = re.search(search, command)
- if match is not None:
- item = match.group('item')
- price = match.group('price')
- quantity = match.group('quantity')
- to_purchase.append((item, price, quantity))
- for x in to_purchase:
- total_sum += float(x[1]) * int(x[2])
- print('Bought furniture:')
- [print(x[0]) for x in to_purchase]
- print(f'Total money spend: {total_sum:.2f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement