Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- furniture_list = []
- pattern = r"(?P<Furniture>[A-Za-z]+)<<(?P<Price>\d+[\.\d+]*)!(?P<Quantity>\d+)"
- total_sum = 0
- while True:
- command = input()
- if command == "Purchase":
- print("Bought furniture:")
- if furniture_list:
- print('\n'.join(furniture_list))
- break
- matches = re.search(pattern, command)
- if matches:
- some_dict = matches.groupdict()
- furniture_list.append(some_dict["Furniture"])
- total_sum += float(some_dict["Price"]) * int(some_dict["Quantity"])
- print(f"Total money spend: {total_sum:.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement