Advertisement
GeorgiLukanov87

SoftUni Bar Income 100/100

Jul 22nd, 2022
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. # SoftUni Bar Income 100/100
  2. # https://judge.softuni.org/Contests/Practice/Index/1744#1
  3.  
  4. import re
  5.  
  6. pattern_name = r'(\%)([A-Z][a-z]+)\1'
  7. pattern_product = r'(\<)([\w+^A-Za-z0-9_]+)(\>)'
  8. pattern_count = r'(\|)([0-9]+)(\|)'
  9. pattern_price = r"(\d+?\.?\d+?)\$(^\$|(?!\$))"
  10.  
  11. extracted_datas = []
  12. command = input()
  13. income = []
  14. while not command == 'end of shift':
  15.     details = command
  16.     matched_names = re.findall(pattern_name, details)
  17.     matched_products = re.findall(pattern_product, details)
  18.     matched_counts = re.findall(pattern_count, details)
  19.     matched_prices = re.findall(pattern_price, details)
  20.  
  21.     if matched_names and matched_products and matched_counts and matched_prices:
  22.  
  23.         name = matched_names[0][1]
  24.         product = matched_products[0][1]
  25.         count = int(matched_counts[0][1])
  26.         price = float(matched_prices[0][0])
  27.  
  28.         total_sum = price * count
  29.         income.append(total_sum)
  30.         extracted_datas = ([name] + [product] + [total_sum])
  31.         print(f"{extracted_datas[0]}: {extracted_datas[1]} - {extracted_datas[2]:.2f}")
  32.         command = input()
  33.     else:
  34.         command = input()
  35.         continue
  36.  
  37. print(f'Total income: {sum(income):.2f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement