Guest User

laundry.py

a guest
Aug 18th, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. class LaundryItem:
  2.     allStates=["soak","wash","rinse","spin","dry","done"]
  3.     def __init__(self):
  4.         self.state=-1
  5.     def nextCycle(self):
  6.         self.state+=1
  7.         if self.state<len(LaundryItem.allStates):
  8.             return LaundryItem.allStates[self.state]
  9.         return LaundryItem.allStates[-1]
  10.  
  11. last=None
  12. def createLaundryItem():
  13.     global last
  14.     while True:
  15.         if (last==None) or (last.state>=len(LaundryItem.allStates)):
  16.             last=LaundryItem()
  17.         return last
  18.  
  19. def main():
  20.     towel=createLaundryItem()
  21.     print(towel.nextCycle())
  22.     print(towel.nextCycle())
  23.     print(towel.nextCycle())
  24.     print(towel.nextCycle())
  25.     print(towel.nextCycle())
  26.     print(towel.nextCycle())
  27.     print(towel.nextCycle())
  28.  
  29. if __name__=="__main__":
  30.     main()
  31.  
Advertisement
Add Comment
Please, Sign In to add comment