Advertisement
Spocoman

02. Ad Astra

Nov 28th, 2023
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. import re
  2.  
  3. regex = r"([|#])([A-Za-z\s]+)\1(\d{2}\/\d{2}\/\d{2})\1(\d{1,5})\1"
  4. matches = re.findall(regex, input())
  5. products = []
  6. sum_calories = 0
  7.  
  8. for m in matches:
  9.     products.append({'name': m[1], 'date': m[2], 'calories': m[3]})
  10.     sum_calories += int(m[3])
  11.  
  12. print(f"You have food to last you for: {sum_calories // 2000} days!")
  13.  
  14. for p in products:
  15.     print(f"Item: {p['name']}, Best before: {p['date']}, Nutrition: {p['calories']}")
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement