Advertisement
KevinOrr

Untitled

Sep 22nd, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. class Dog():
  2.     def __init__(self, name, breed):
  3.         self.name = name
  4.         self.breed = breed
  5.  
  6.     def rollover(self, will_there_be_a_treat):
  7.         if will_there_be_a_treat:
  8.             print(self.name + ' rolled over')
  9.         else:
  10.             print(self.name + ' is begging')
  11.  
  12.     def sniff(self):
  13.         if self.breed == 'Bloodhound':
  14.             print(self.name + ' found a dead body in your attic')
  15.         else:
  16.             print(self.name + ' started sniffing your cat\'s butt')
  17.  
  18.     def sleep(self, length):
  19.         time.sleep(length)
  20.         print(self.name + ' slept for ' + str(length) + ' seconds and is now awake')
  21.  
  22.     def play_dead(self, will_there_be_a_treat):
  23.         if will_there_be_a_treat:
  24.             print(self.name + ' played dead')
  25.         else:
  26.             print(self.name + ' killed you')
  27.  
  28.            
  29. ## Create a dog named Fido
  30.  
  31. fido = Dog('Fido', 'Mutt')
  32.  
  33. fido.rollover(True)
  34. # Fido rolled over
  35.  
  36. fido.sniff()
  37. # Fido started sniffing your cat's butt
  38.  
  39. fido.sleep(3)
  40. # Fido slept for 3 seconds and is now awake
  41.  
  42. fido.play_dead(False)
  43. # Fido killed you
  44.  
  45.  
  46. ## Now for Daisy
  47.  
  48. daisy = Dog('Daisy', 'Bloodhound')
  49.  
  50. daisy.rollover(False)
  51. # Daisy is begging
  52.  
  53. daisy.sniff()
  54. # Daisy found a dead body in your attic
  55.  
  56. daisy.sleep(2)
  57. # Daisy slept for 2 seconds and is now awake
  58.  
  59. daisy.play_dead(True)
  60. # Daisy played dead
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement