viligen

softuni_bar_income

Nov 18th, 2021
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import re
  2.  
  3. pattern = r"%([A-Z][a-z]+)%[^|$%]*<(\w+)>[^|$%]*\|(\d+)\|[^|$%0-9]*(\d+(\.\d*)?)\$$"
  4. total_income = 0
  5. while True:
  6.     data = input()
  7.     if data == "end of shift":
  8.         break
  9.     matches = re.finditer(pattern, data)
  10.     name = ""
  11.     product = ""
  12.     count = 0
  13.     price = 0
  14.     for match in matches:
  15.         if match.group(1) and match.group(2) and match.group(3) and match.group(4):
  16.             name = match.group(1)
  17.             product = match.group(2)
  18.             count = int(match.group(3))
  19.             price = float(match.group(4))
  20.  
  21.         print(f"{name}: {product} - {count * price:.2f}")
  22.     total_income += count * price
  23. print(f"Total income: {total_income:.2f}")
  24.  
Advertisement
Add Comment
Please, Sign In to add comment