viligen

ad_astra

Nov 25th, 2021
438
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2.  
  3. pattern = r"(\||#)([A-Za-z\s]+)(\1)(\d{2}\/\d{2}\/\d{2})(\1)(10000|\d{1,4})(\1)"
  4.  
  5. total_cal = 0
  6. days = 0
  7.  
  8. data = input()
  9.  
  10. matches = re.finditer(pattern, data)
  11.  
  12. for match_ in matches:
  13.     if match_.group(6):
  14.         calories = int(match_.group(6))
  15.         total_cal += calories
  16.  
  17. days = total_cal//2_000
  18. print(f"You have food to last you for: {days} days!")
  19.  
  20. matches = re.finditer(pattern, data)
  21.  
  22. for match in matches:
  23.     item_name = match.group(2)
  24.     exp_date = match.group(4)
  25.     calories = match.group(6)
  26.     print(f"Item: {item_name}, Best before: {exp_date}, Nutrition: {calories}")
  27.  
RAW Paste Data