-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDog Class.py
43 lines (35 loc) · 1.32 KB
/
Dog Class.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from time import sleep, time
from random import choice
class Dog:
def __init__(self, name, breed, color, weightKg, gender):
self.breed = breed
self.name = name
self.gender = gender
self.color = color
self.weight = weightKg
self.birthday = time() # strftime('%S')
def age(self):
age = int(time()) - int(self.birthday)
print(self.name, "is", age, "seconds old")
def bark(self):
for i in range(0, (int(self.weight / 2))):
print(choice(["Woof", "Grr", "howl", "arf", "ruff", "bow-wow"]))
c = choice([0, 2, 3, 1, 5])
sleep(c)
# add method to Dog class
def feed(self, foodGrams):
self.weight += (foodGrams / 1000) / 2
def meet(self, other):
print(self.name, "meet", other.name, "in the dog park")
if other.gender == "Male" and self.gender == "Female":
print(self.name, "has a crush on", other.name)
else:
print(self.name, "and", other.name, "are going to play chase")
Yorkie = Dog("JJ", "Yorkie", "Tan", 2, "Male")
Yorkie.bark()
Yorkie.age()
Yorkie.feed(100)
print("My Yorkie weighs", Yorkie.weight, "Kg")
# create an instance of the dog class name the dog "Monty"
GermanShep = Dog("Jenny", "German Shepard", "Brown", 29, "Female")
GermanShep.meet(Yorkie)