fork download
  1. class Pipe:
  2. state = True
  3. def draw(self):
  4. print("I am a pipe.")
  5. if(self.state):
  6. print("I am enabled.")
  7. else:
  8. print("I am disabled.")
  9.  
  10.  
  11. class FastPipe(Pipe):
  12. speed = 1.0
  13. def draw(self):
  14. Pipe.draw(self)
  15. print("I transport things quickly.")
  16. print("My speed is", self.speed)
  17.  
  18.  
  19. pipe = Pipe()
  20. pipe.state = False
  21. pipe.draw()
  22. print("")
  23. pipe.__class__ = FastPipe
  24. pipe.speed += 0.5
  25. pipe.draw()
  26.  
Success #stdin #stdout 0.02s 5804KB
stdin
Standard input is empty
stdout
I am a pipe.
I am disabled.

I am a pipe.
I am disabled.
I transport things quickly.
My speed is 1.5