Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- pattern = r'(?P<symbol>[#|/])(?P<name>[a-zA-Z\s]+)(?P=symbol)(?P<date>\d{2}/\d{2}/\d{2})(?P=symbol)(?P<calories>\d{1,5})(?P=symbol)'
- text = input()
- total_calories = 0
- matches = list(re.finditer(pattern, text))
- for match in matches:
- total_calories += int(match.group('calories'))
- print(f'You have food to last you for: {total_calories//2000} days!')
- for match in matches:
- print(f"Item: {match.group('name')}, Best before: {match.group('date')}, Nutrition: {match.group('calories')}")
Advertisement
Add Comment
Please, Sign In to add comment