Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. class Duck:
  2. def quack(self):
  3. print("這鴨子在呱呱叫")
  4.  
  5. def feathers(self):
  6. print("這鴨子擁有白色與灰色羽毛")
  7.  
  8.  
  9. class Person:
  10. def quack(self):
  11. print("這人正在模仿鴨子")
  12.  
  13. def feathers(self):
  14. print("這人在地上拿起1根羽毛然後給其他人看")
  15.  
  16.  
  17. def in_the_forest(duck):
  18. duck.quack()
  19. duck.feathers()
  20.  
  21.  
  22. def game():
  23.  
  24. donald = Duck()
  25. john = Person()
  26. in_the_forest(donald)
  27. in_the_forest(john) # put Person in as Duck, consider behavior only, excluding what class actually is.
  28.  
  29. game()
  30. """
  31. 這鴨子在呱呱叫
  32. 這鴨子擁有白色與灰色羽毛
  33. 這人正在模仿鴨子
  34. 這人在地上拿起1根羽毛然後給其他人看
  35. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement