Advertisement
Jorell_Ramos_Sinaga

dog.py

Jan 13th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. class Dog:
  2.  
  3.     def __init__(self, name, variation, color, eye=2, tail=1):
  4.         self.name = name
  5.         self.variation = variation
  6.         self.color = color
  7.         self.eye = eye
  8.         self.age = 0
  9.         self.tail = tail
  10.         self.bark()
  11.  
  12.     def sit(self):
  13.         print(f"{self.name} sedang duduk santuy sambil nge-vape")
  14.  
  15.     def cry(self):
  16.         print(f"{self.name} : hikz ... >.<")
  17.  
  18.     def bark(self):
  19.         print(f"Woof Woof ....")
  20.  
  21.     def sleep(self):
  22.         print(f"{self.name} ngantuk zzzZZZZZ")
  23.  
  24.     def eat(self):
  25.         print(f"{self.name} lapar... *monch* *monch*")
  26.  
  27.     def change_color(self, new_color):
  28.         if new_color.lower() == 'white':
  29.             print('Sorry, anjing ga bisa warna putih bos..')
  30.         else:
  31.             self.color = new_color
  32.             print(f'Ubah warna selesai jadi warna {self.color}')
  33.  
  34.     def increment_age(self):
  35.         self.age += 1
  36.  
  37.     def change_number_of_tail(self, number):
  38.         self.tail = number
  39.  
  40. dog_1 = Dog('Willie', 'Kintamani', 'Blue', eye=3)
  41. print(dog_1.name)
  42. dog_1.sit()
  43. dog_1.cry()
  44. dog_1.sleep()
  45. dog_1.eat()
  46. dog_1.name = 'Tedjo'
  47. print(dog_1.name)
  48. dog_1.sit()
  49. for i in range(5):
  50.     dog_1.increment_age()
  51. print(dog_1.age)
  52. dog_1.change_number_of_tail("2")
  53. print(dog_1.tail)
  54.  
  55. print(dog_1.color)
  56. dog_1.change_color("black")
  57. print(dog_1.color)
  58.  
  59. dog_2 = Dog('Bagus', 'Lokal', 'Brown')
  60. print(dog_2.name)
  61. dog_2.sit()
  62. dog_2.cry()
  63. dog_2.sleep()
  64. dog_2.eat()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement