Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- pattern = r"(\||#)([A-Za-z\s]+)(\1)(\d{2}\/\d{2}\/\d{2})(\1)(10000|\d{1,4})(\1)"
- total_cal = 0
- days = 0
- data = input()
- matches = re.finditer(pattern, data)
- for match_ in matches:
- if match_.group(6):
- calories = int(match_.group(6))
- total_cal += calories
- days = total_cal//2_000
- print(f"You have food to last you for: {days} days!")
- matches = re.finditer(pattern, data)
- for match in matches:
- item_name = match.group(2)
- exp_date = match.group(4)
- calories = match.group(6)
- print(f"Item: {item_name}, Best before: {exp_date}, Nutrition: {calories}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement