Skip to content

Commit 0481818

Browse files
committed
The Wheel Class completed (p34)
1 parent e3abed4 commit 0481818

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

bike.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
import math
23

34

45
class Wheel(object):
@@ -10,17 +11,20 @@ def __init__(self, rim, tyre):
1011
def diameter(self):
1112
return self.rim + (self.tyre * 2)
1213

14+
def circumference(self):
15+
return self.diameter() * math.pi
16+
1317

1418
def wheelify(data):
1519
return [Wheel(cell[0], cell[1]) for cell in data]
1620

1721

1822
class Gear(object):
1923

20-
def __init__(self, chainring, cog, rim, tyre):
24+
def __init__(self, chainring, cog, wheel=None):
2125
self.chainring = chainring
2226
self.cog = cog
23-
self.wheel = Wheel(rim, tyre)
27+
self.wheel = wheel
2428

2529
def ratio(self):
2630
return self.chainring / float(self.cog)
@@ -35,14 +39,17 @@ def __init__(self, data):
3539
self.wheels = wheelify(data)
3640

3741
def diameters(self):
38-
return [self.diameter(wheel) for wheel in self.wheels]
39-
40-
def diameter(self, wheel):
41-
return wheel.rim + (wheel.tyre * 2)
42+
return [wheel.diameter() for wheel in self.wheels]
4243

4344

44-
print Gear(52, 11, 26, 1.5).gear_inches()
45-
print Gear(52, 11, 24, 1.25).gear_inches()
45+
print Gear(52, 11, Wheel(26, 1.5)).gear_inches()
46+
print Gear(52, 11, Wheel(24, 1.25)).gear_inches()
4647

4748
data = [[622, 20], [622, 23], [559, 30], [559, 40]]
4849
print RevealingReferences(data).diameters()
50+
51+
wheel = Wheel(26, 1.5)
52+
print wheel.circumference()
53+
54+
print Gear(52, 11, wheel).gear_inches()
55+
print Gear(52, 11).ratio()

0 commit comments

Comments
 (0)