Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- customers = []
- product = []
- final_price = []
- while True:
- text = input()
- if text == "end of shift":
- break
- pattern = r"%(?P<Customer>[A-Z][a-z]+)%[^\|\$\%\.]*(?P<Product><\w+)>[^\|\$\%\.]*\|(?P<Count>\d+)\|[A-Za-z\s]*(?P<Price>\d+(\.\d+)*)\$"
- matches = re.finditer(pattern, text)
- for match in matches:
- some_dict = match.groupdict()
- if None not in some_dict.values():
- customers.append(some_dict["Customer"])
- product.append(some_dict["Product"][1:])
- final_price.append(int(some_dict["Count"]) * float(some_dict["Price"]))
- total_income = sum(final_price)
- for index in range(len(customers)):
- print(f"{customers[index]}: {product[index]} - {final_price[index]:.2f}")
- print(f"Total income: {total_income:.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement