Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 02. SoftUni Bar Income Regular Expressions - More Exercises 100/100
- # https://judge.softuni.org/Contests/Practice/Index/1744#1
- import re
- pattern_name = r'(\%)([A-Z][a-z]+)\1'
- pattern_product = r'(\<)([\w+^A-Za-z0-9_]+)(\>)'
- pattern_count = r'(\|)([0-9]+)(\|)'
- pattern_price = r"(\d+?\.?\d+?)\$(^\$|(?!\$))"
- extracted_datas = []
- command = input()
- income = []
- while not command == 'end of shift':
- details = command
- matched_names = re.findall(pattern_name, details)
- matched_products = re.findall(pattern_product, details)
- matched_counts = re.findall(pattern_count, details)
- matched_prices = re.findall(pattern_price, details)
- if matched_names and matched_products and matched_counts and matched_prices:
- name = matched_names[0][1]
- product = matched_products[0][1]
- count = int(matched_counts[0][1])
- price = float(matched_prices[0][0])
- total_sum = price * count
- income.append(total_sum)
- extracted_datas = ([name] + [product] + [total_sum])
- print(f"{extracted_datas[0]}: {extracted_datas[1]} - {extracted_datas[2]:.2f}")
- command = input()
- else:
- command = input()
- continue
- print(f'Total income: {sum(income):.2f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement