Skip to content

Commit d1b58a5

Browse files
committed
indentation to spaces
Signed-off-by: Adam McNicol <[email protected]>
1 parent 58d0f17 commit d1b58a5

25 files changed

+907
-907
lines changed
5.55 KB
Binary file not shown.

__pycache__/cow_class.cpython-33.pyc

1.61 KB
Binary file not shown.

__pycache__/crop_class.cpython-33.pyc

5.49 KB
Binary file not shown.
1.84 KB
Binary file not shown.
1.63 KB
Binary file not shown.
1.85 KB
Binary file not shown.

animal_class.py

+92-92
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
11
import random
22

33
class Animal:
4-
"""a generic animal"""
4+
"""a generic animal"""
55

6-
#constructor
7-
def __init__(self,growth_rate,food_need,water_need,name):
8-
#set the attributes with an initial value
6+
#constructor
7+
def __init__(self,growth_rate,food_need,water_need,name):
8+
#set the attributes with an initial value
99

10-
self._weight = 0
11-
self._days_growing = 0
12-
self._growth_rate = growth_rate
13-
self._food_need = food_need
14-
self._water_need = water_need
15-
self._status = "Baby"
16-
self._type = "Generic"
17-
self.name = name
10+
self._weight = 0
11+
self._days_growing = 0
12+
self._growth_rate = growth_rate
13+
self._food_need = food_need
14+
self._water_need = water_need
15+
self._status = "Baby"
16+
self._type = "Generic"
17+
self.name = name
1818

19-
#the above attributes are prefixed with an underscore to indicate that they should not be
20-
#accessed directly from outwith the class except for name which can be changed freely
19+
#the above attributes are prefixed with an underscore to indicate that they should not be
20+
#accessed directly from outwith the class except for name which can be changed freely
2121

22-
#method to indicate the needs of the animal
23-
def needs(self):
24-
#return a dictionary containing the food and water needs
25-
return {'food need':self._food_need,'water need':self._water_need}
22+
#method to indicate the needs of the animal
23+
def needs(self):
24+
#return a dictionary containing the food and water needs
25+
return {'food need':self._food_need,'water need':self._water_need}
2626

27-
#method to provide information about the current state of the animal
28-
def report(self):
29-
#return a dictionary containing name,type,status, weight and days growing
30-
return {'name':self.name,'type':self._type,'status':self._status,'weight':self._weight,'days growing':self._days_growing}
27+
#method to provide information about the current state of the animal
28+
def report(self):
29+
#return a dictionary containing name,type,status, weight and days growing
30+
return {'name':self.name,'type':self._type,'status':self._status,'weight':self._weight,'days growing':self._days_growing}
3131

32-
#the underscore indicates that this method should not be called from outwith the class
33-
def _update_status(self):
34-
if self._weight > 30:
35-
self._status = "Prime"
36-
elif self._weight > 15:
37-
self._status = "Fine"
38-
elif self._weight > 10:
39-
self._status = "Poor"
40-
elif self._weight >= 0:
41-
self._status = "Baby"
32+
#the underscore indicates that this method should not be called from outwith the class
33+
def _update_status(self):
34+
if self._weight > 30:
35+
self._status = "Prime"
36+
elif self._weight > 15:
37+
self._status = "Fine"
38+
elif self._weight > 10:
39+
self._status = "Poor"
40+
elif self._weight >= 0:
41+
self._status = "Baby"
4242

43-
def grow(self,food,water):
44-
if food >= self._food_need and water >= self._water_need:
45-
self._weight += self._growth_rate
46-
#increment days growing
47-
self._days_growing += 1
48-
#update the status
49-
self._update_status()
43+
def grow(self,food,water):
44+
if food >= self._food_need and water >= self._water_need:
45+
self._weight += self._growth_rate
46+
#increment days growing
47+
self._days_growing += 1
48+
#update the status
49+
self._update_status()
5050

5151
def manual_grow(self):
52-
#get the food and water values from the user
53-
valid = False
54-
while not valid:
55-
try:
56-
food = int(input("Please enter a food value (1-10): "))
57-
if 1 <= food <= 10:
58-
valid = True
59-
else:
60-
print("Value entered not valid - please enter a value between 1 and 10")
61-
except ValueError:
62-
print("Value entered not valid - please enter a value between 1 and 10")
63-
valid = False
64-
while not valid:
65-
try:
66-
water = int(input("Please enter a water value (1-10): "))
67-
if 1 <= water <= 10:
68-
valid = True
69-
else:
70-
print("Value entered not valid - please enter a value between 1 and 10")
71-
except ValueError:
72-
print("Value entered not valid - please enter a value between 1 and 10")
73-
#grow the animal
74-
self.grow(food,water)
52+
#get the food and water values from the user
53+
valid = False
54+
while not valid:
55+
try:
56+
food = int(input("Please enter a food value (1-10): "))
57+
if 1 <= food <= 10:
58+
valid = True
59+
else:
60+
print("Value entered not valid - please enter a value between 1 and 10")
61+
except ValueError:
62+
print("Value entered not valid - please enter a value between 1 and 10")
63+
valid = False
64+
while not valid:
65+
try:
66+
water = int(input("Please enter a water value (1-10): "))
67+
if 1 <= water <= 10:
68+
valid = True
69+
else:
70+
print("Value entered not valid - please enter a value between 1 and 10")
71+
except ValueError:
72+
print("Value entered not valid - please enter a value between 1 and 10")
73+
#grow the animal
74+
self.grow(food,water)
7575

7676
def auto_grow(self,days):
77-
#grow the animal automatically over 30 days
78-
for day in range(days):
79-
food = random.randint(1,10)
80-
water = random.randint(1,10)
81-
self.grow(food,water)
77+
#grow the animal automatically over 30 days
78+
for day in range(days):
79+
food = random.randint(1,10)
80+
water = random.randint(1,10)
81+
self.grow(food,water)
8282

8383
def displayMenu():
8484
print('1. Grow manually over 1 day')
@@ -102,32 +102,32 @@ def getMenuChoice():
102102
return choice
103103

104104
def manage_animal(self):
105-
print('This is animal management program')
106-
print()
107-
noexit = True
108-
while noexit:
109-
displayMenu()
110-
option = getMenuChoice()
111-
print()
112-
if option == 1:
113-
manual_grow(self)
114-
print()
115-
elif option == 2:
116-
auto_grow(self,30)
117-
print()
118-
elif option == 3:
119-
print(self.report())
120-
print()
121-
elif option == 0:
122-
noexit = False
123-
print()
124-
print('Thank you for using the animal management program')
105+
print('This is animal management program')
106+
print()
107+
noexit = True
108+
while noexit:
109+
displayMenu()
110+
option = getMenuChoice()
111+
print()
112+
if option == 1:
113+
manual_grow(self)
114+
print()
115+
elif option == 2:
116+
auto_grow(self,30)
117+
print()
118+
elif option == 3:
119+
print(self.report())
120+
print()
121+
elif option == 0:
122+
noexit = False
123+
print()
124+
print('Thank you for using the animal management program')
125125

126126
def main():
127-
#instaniate the class
128-
new_animal = Animal(1,4,5,"Sally")
129-
#test to see whether it works or not
130-
manage_animal(new_animal)
127+
#instaniate the class
128+
new_animal = Animal(1,4,5,"Sally")
129+
#test to see whether it works or not
130+
manage_animal(new_animal)
131131

132132
if __name__ == '__main__':
133-
main()
133+
main()

cow_class.py

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
from animal_class import *
22

33
class Cow(Animal):
4-
"""A simulation of a Cow"""
4+
"""A simulation of a Cow"""
55

6-
#constructor
7-
def __init__(self,name):
8-
#call the parent class constructor with default values for Cow
9-
#growth rate = 2; food need = 5, water need = 4
10-
super().__init__(2,5,4,name)
11-
self._type = "Cow" #override the parent class attribute with new value
6+
#constructor
7+
def __init__(self,name):
8+
#call the parent class constructor with default values for Cow
9+
#growth rate = 2; food need = 5, water need = 4
10+
super().__init__(2,5,4,name)
11+
self._type = "Cow" #override the parent class attribute with new value
1212

13-
#override the grow method from the parent class
14-
def grow(self,food,water):
15-
if food > self._food_need:
16-
self._weight += self._growth_rate * 1.1
17-
elif food == self._food_need and water >= self._water_need:
18-
self._weight += self._growth_rate
19-
#increment days growing
20-
self._days_growing += 1
21-
#update the status
22-
self._update_status()
13+
#override the grow method from the parent class
14+
def grow(self,food,water):
15+
if food > self._food_need:
16+
self._weight += self._growth_rate * 1.1
17+
elif food == self._food_need and water >= self._water_need:
18+
self._weight += self._growth_rate
19+
#increment days growing
20+
self._days_growing += 1
21+
#update the status
22+
self._update_status()
2323

2424
def main():
25-
#instaniate the class
26-
new_cow = Cow("Jim")
27-
#test to see whether it works or not
28-
manage_animal(new_cow)
25+
#instaniate the class
26+
new_cow = Cow("Jim")
27+
#test to see whether it works or not
28+
manage_animal(new_cow)
2929

3030
if __name__ == '__main__':
31-
main()
31+
main()

0 commit comments

Comments
 (0)