Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- regex = r"([|#])([A-Za-z\s]+)\1(\d{2}\/\d{2}\/\d{2})\1(\d{1,5})\1"
- matches = re.findall(regex, input())
- products = []
- sum_calories = 0
- for m in matches:
- products.append({'name': m[1], 'date': m[2], 'calories': m[3]})
- sum_calories += int(m[3])
- print(f"You have food to last you for: {sum_calories // 2000} days!")
- for p in products:
- print(f"Item: {p['name']}, Best before: {p['date']}, Nutrition: {p['calories']}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement