Sichanov

softuni_bar_income

Nov 15th, 2021
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import re
  2.  
  3. money = {}
  4. command = input()
  5. pattern_new = r"([^|$%.]+)?%(?P<name>[A-Z][a-z]+)%([^|$%.]+)?<(?P<product>[a-zA-Z]+)>([^|$%.]+)?\|([^|$%.\d]+)?(?P<quantity>\d+)([^|$%.\d]+)?\|([^|$%.\d]+)?(?P<price>\d+(\.\d+)?)\$([^|$%.]+)?"
  6. while not command == 'end of shift':
  7.     match = re.match(pattern_new, command)
  8.     if match:
  9.         current_match = match.groupdict()
  10.         money[current_match['name']] = {current_match['product']: int(current_match['quantity']) * float(current_match['price'])}
  11.     command = input()
  12. total = 0
  13. for k, v in money.items():
  14.     print(f"{k}: {''.join(f'{kk} - {vv:.2f}' for kk,vv in v.items())}")
  15.     for values in v.values():
  16.         total += values
  17.  
  18. print(f'Total income: {total:.2f}')
Advertisement
Add Comment
Please, Sign In to add comment