bl00dt3ars

02. Ad Astra

Aug 18th, 2021
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import re
  2.  
  3. 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)'
  4. text = input()
  5. total_calories = 0
  6. matches = list(re.finditer(pattern, text))
  7. for match in matches:
  8.     total_calories += int(match.group('calories'))
  9.  
  10. print(f'You have food to last you for: {total_calories//2000} days!')
  11. for match in matches:
  12.     print(f"Item: {match.group('name')}, Best before: {match.group('date')}, Nutrition: {match.group('calories')}")
Advertisement
Add Comment
Please, Sign In to add comment