1. class Cookie:
  2. def __init__(self, name, fix, duration):
  3. self.name = name # Cookie name
  4. self.fix = fix # What the cookie fixes
  5. self.duration = duration #How long the fix lasts
  6. def __repr__(self): #For easy printing/debugging
  7. return f"Cookie(name='{self.name}', fix='{self.fix}', duration={self.duration})"
  8. def create_cookie_structure():
  9. """Creates a nested structure of cookies."""
  10. cookies = {
  11. "headache": Cookie("Peppermint Patty", "Headache relief", 2),
  12. "fatigue": Cookie("Chocolate Chunk", "Energy boost", 1),
  13. "sadness": Cookie("Ginger Snap", "Mood lifting", 3),
  14. "stress": Cookie("Lemon Crumb", "Calming effect", 1.5),
  15. "low_energy": Cookie("Oatmeal Raisin", "Sustained energy", 2.5)
  16. }
  17. # Group cookies by category (optional - for more complex structures)
  18. categories = {
  19. "headache": cookies["headache"],
  20. "energy": [cookies["fatigue"], cookies["low_energy"]],
  21. "mood": [cookies["sadness"]],
  22. "relaxation": [cookies["stress"]]
  23. }
  24. return categories #Return the dictionary of cookies
  25. if __name__ == '__main__':
  26. cookie_structure = create_cookie_structure()
  27. print(cookie_structure) #Prints the entire structure
  28. print(cookie_structure["headache"].fix) #Prints the fix for headaches

Add your comment