Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- customers = []
- def check_name(i: str):
- search = r'%(?P<name>[A-Z][a-z]+)%'
- match = re.search(search, i)
- if match is None:
- return None
- else:
- return match.group('name')
- def check_product(i: str):
- search = r'<(?P<item>[\w]+)>'
- match = re.search(search, i)
- if match is None:
- return None
- else:
- return match.group('item')
- def check_quantity(i: str):
- search = r'\|(?P<number>[0-9]+)\|'
- match = re.search(search, i)
- if match is None:
- return None
- else:
- return int(match.group('number'))
- def check_price(i: str):
- search = r'((?P<price>[0-9]+(\.[0-9]+)*)\$)'
- match = re.search(search, i)
- if match is None:
- return None
- else:
- return float(match.group('price'))
- while True:
- info = input()
- if info == 'end of shift':
- break
- name = check_name(info)
- product = check_product(info)
- quantity = check_quantity(info)
- price = check_price(info)
- valid = name and product and quantity and price
- if valid:
- customers.append([name, product, quantity * price])
- total_sum = sum([x[2] for x in customers])
- # Тук ако ползвам речници няма да стане
- # Трябва да принтирам всеки валиден вход дори и да се повтаря, а с речници принтирам само уникални.
- [print(f'{x[0]}: {x[1]} - {x[2]:.2f}') for x in customers]
- print(f'Total income: {total_sum:.2f}')
Advertisement
Add Comment
Please, Sign In to add comment