ivantanchev

more regex 2 zadacha

Aug 5th, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. import re
  2.  
  3. command = input()
  4. total_sum = 0
  5. list_of_products = {}
  6. while command != "end of shift":
  7.  
  8.     pattern = r'(%([A-Z][a-z]+)%)(\w*)(<(\w+)>)(\w*)(\|([0-9]+)\|)(\D*)((\d.+)(\$))'
  9.     matches = re.finditer(pattern, command)
  10.  
  11.     for match in matches:
  12.         name = match.group(2)
  13.         product = match.group(5)
  14.         quantity = int(match.group(8))
  15.         price = match.group(11)
  16.         total_sum += quantity * float(price)
  17.         current_sum = quantity * float(price)
  18.         list_of_products[name] = [product, current_sum]
  19.     command = input()
  20. for key, values in list_of_products.items():
  21.     name = key
  22.     product = values[0]
  23.     price = values[1]
  24.     print(f"{name}: {product} - {price:.2f}")
  25. print(f"Total income: {total_sum:.2f}")
  26.  
Advertisement
Add Comment
Please, Sign In to add comment