Advertisement
go6odn28

softuni_bar_income

Mar 22nd, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import re
  2. customers = []
  3. product = []
  4. final_price = []
  5.  
  6. while True:
  7.     text = input()
  8.     if text == "end of shift":
  9.         break
  10.     pattern = r"%(?P<Customer>[A-Z][a-z]+)%[^\|\$\%\.]*(?P<Product><\w+)>[^\|\$\%\.]*\|(?P<Count>\d+)\|[A-Za-z\s]*(?P<Price>\d+(\.\d+)*)\$"
  11.     matches = re.finditer(pattern, text)
  12.     for match in matches:
  13.         some_dict = match.groupdict()
  14.         if None not in some_dict.values():
  15.             customers.append(some_dict["Customer"])
  16.             product.append(some_dict["Product"][1:])
  17.             final_price.append(int(some_dict["Count"]) * float(some_dict["Price"]))
  18. total_income = sum(final_price)
  19. for index in range(len(customers)):
  20.     print(f"{customers[index]}: {product[index]} - {final_price[index]:.2f}")
  21. print(f"Total income: {total_income:.2f}")
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement