-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPetsClassLessons.py
More file actions
103 lines (75 loc) · 2.34 KB
/
PetsClassLessons.py
File metadata and controls
103 lines (75 loc) · 2.34 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#Classes - Pets: Lessons A - D
class Pets:
def __init__(self, n, a, h, p):
self.name = n
self.age = a
self.hunger = h
self.playful = p
#getters
def getName(self):
return self.name
def getAge(self):
return self.age
def getHunger(self):
return self.hunger
def getPlayful(self):
return self.playful
#setters
def setName(self, x):
self.name = x
def setAge(self, Age):
self.age = Age
def setHunger(self, hunger):
self.hunger = hunger
def setPlayful(self, playful):
self.playful = playful
def __str__(self):
return (self.name + " is " + str(self.age) + " years old.")
# Pet1 = Pets("Fido", 43, False, True)
# print(Pet1.getName())
# print(Pet1.getPlayful())
# Pet1.setName("Snowball")
# print(Pet1.getName())
# print(Pet1.name)
# Pet1.name = "Jim"
# print(Pet1.name)
# print(Pet1)
class Dog(Pets):
def __init__(self, name, age, hunger, playful, breed, favoriteToy):
Pets.__init__(self, name, age, hunger, playful)
self.breed = breed
self.favoriteToy = favoriteToy
def wantsToPlay(self):
if self.playful == True:
return ("Dog wants to play with " + self.favoriteToy)
else:
return ("The dog doesn't want to play.")
class Cat(Pets):
def __init__(self, name, age, hunger, playful, place):
Pets.__init__(self, name, age, hunger, playful)
self.favPlaceToSit = place
def wantsToSit(self):
if self.playful == True:
print("The cat " + self.name + " wants to sit in their favortie place, the " + self.favPlaceToSit)
else:
print("The cat wants to play.")
class human:
def __init__(self, name, pets):
self.name = name
self.pets = pets
def hasPets(self):
if len(self.pets) != 0:
return "yes"
else:
return "no"
huskyDog = Dog("Bill", 5, False, False, "Husky", "Rope")
play = huskyDog.wantsToPlay()
print(play)
typicalCat = Cat("William", 17, False, True, "chair.")
typicalCat.wantsToSit()
print(typicalCat)
print(huskyDog)
yourAverageHuman = human("Alice", [huskyDog, typicalCat])
hasPets = yourAverageHuman.hasPets()
print(hasPets + " " + str(len(yourAverageHuman.pets)) + " pets.")
print(yourAverageHuman.pets[1])