fork download
  1. class RobExample: # define the class
  2.  
  3. def __init__(self,color,shape): #tell the object what to do when initialized
  4. self.color = color;
  5. self.shape = shape;
  6.  
  7. def drawShape(self):
  8. print "I am printing a", self.color, self.shape
  9.  
  10. def changeShape(self, shape):
  11. self.shape = shape
  12. self.drawShape()
  13.  
  14. def changeColor(self, color):
  15. self.color = color
  16. self.drawShape()
  17.  
  18. def changeBoth(self, color, shape):
  19. self.color = color
  20. self.shape = shape
  21. self.drawShape()
  22.  
  23. def main():
  24. shape = RobExample("red","circle")
  25. shape2 = RobExample("blue", "horse")
  26. shape3 = RobExample("red", "house")
  27.  
  28. shape.drawShape()
  29. shape2.drawShape()
  30. shape3.drawShape()
  31.  
  32. shape.changeShape("square")
  33. shape2.changeColor("turqoise")
  34. shape3.changeBoth("yellow","banna")
  35.  
  36. main()
  37.  
  38.  
Success #stdin #stdout 0.08s 10864KB
stdin
Standard input is empty
stdout
I am printing a red circle
I am printing a blue horse
I am printing a red house
I am printing a red square
I am printing a turqoise horse
I am printing a yellow banna