classic_games

Infinite Coffee Drinking BUT this time, it works.

Sep 2nd, 2025
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | Source Code | 0 0
  1. class Coffee:
  2.     # This class assumes you drink a full cup of coffee in 2 gulps
  3.     gulp_phases = {
  4.         "full": 0,
  5.         "half": 1,
  6.         "empty": 2
  7.     }
  8.  
  9.     def __init__(self, coffee_mug: str):
  10.         """
  11.        param: coffee_mug: String to declare the fullness of the coffee. Allowed values are:
  12.             - full
  13.             - half
  14.             - empty
  15.        """
  16.         if coffee_mug not in self.gulp_phases:
  17.             print("Invalid coffee mug state. Defaulting to full.")
  18.             self.coffee_mug = "full"
  19.             self.gulps = 0
  20.         else:  # If "coffee_mug" is valid
  21.             self.coffee_mug = coffee_mug
  22.             self.gulps = self.gulp_phases[self.coffee_mug]
  23.  
  24.     def get_coffee_state(self):
  25.         return self.coffee_mug
  26.    
  27.     def set_coffee_state(self, current_gulps: int):
  28.         for mug, gulp in self.gulp_phases.items():
  29.             if gulp == current_gulps:
  30.                 return mug
  31.         return "empty" # If nothing is found. But it might never happen
  32.    
  33.     def refill_coffee(self):
  34.         self.coffee_mug = "full"
  35.         self.gulps = 0
  36.  
  37.     def drink(self):
  38.         # Check the state of the coffee (i.e., full, empty)
  39.         state = self.get_coffee_state()
  40.  
  41.         if state != "empty":
  42.             self.gulps = self.gulps + 1
  43.             self.coffee_mug = self.set_coffee_state(self.gulps)
  44.         else:  # If coffee_mug is empty
  45.             self.refill_coffee()
  46.  
  47. if __name__ == "__main__":
  48.     my_coffee = Coffee(coffee_mug="full")
  49.    
  50.     while True:
  51.         print(f"Coffee is {my_coffee.get_coffee_state()} ({my_coffee.gulps} gulps)")
  52.         my_coffee.drink()
  53.  
  54.  
  55.  
  56. # I wrote this piece of code because I saw a meme online on Facebook. A coffee mug with code on it to infinatly drink coffee. But that piece of code is broken. It's bad. Meme link: https://www.facebook.com/groups/182314357252077/permalink/1213079200842249/
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment