Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def is_valid_purchase(name, product, quantity, price):
- return bool(name and product and quantity and price)
- def is_valid_name_customer(name):
- pattern = re.compile(r"^\%(?P<name>[A-Z][a-z]+)\%(?:[^$\|%\.<>]+)?")
- match = pattern.search(name)
- return match.group("name") if match else None
- def is_valid_product(product):
- if is_valid_name_customer:
- pattern = re.compile(r"(?:[^\$\|\%\.\<\>]+)?\<(?P<product>\w+)\>(?:[^$\|%\.<>]+)?") # мачнато име, но първо трябва да откаже името на купувача
- match = pattern.search(product)
- return match.group("product") if match else None
- return None
- def is_valid_quantity(qty):
- pattern = re.compile(r"(?:[^$\|%\.<>]+)?\|(?P<qty>\d+)\|(?:[^$\|%\.<>]+)?")
- match = pattern.search(qty)
- return match.group("qty") if match else 0
- def is_valid_price(price):
- pattern = re.compile(r"\|(?P<price>\d+\.\d+)\$(?:[^$\|%\.<>]+)?")
- match = pattern.search(price)
- return match.group("price") if match else 0
- total_income = 0
- while True:
- text = input()
- if text == 'end of shift':
- break
- valid_name = is_valid_name_customer(text)
- valid_product = is_valid_product(text)
- valid_quantity = is_valid_quantity(text)
- valid_price = is_valid_price(text)
- total_price = int(valid_quantity) * float(valid_price)
- print(f"{valid_name}: {valid_product} - {total_price:.2f}")
- total_income += total_price
- print(f"Total income: {total_income:.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement