-
Notifications
You must be signed in to change notification settings - Fork 5
/
footwear.py
95 lines (80 loc) · 2.47 KB
/
footwear.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
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
class Footwear:
"""
>>> f = Footwear('Sling-back', 8.5, '1234-0')
>>> f.style
'Sling-back'
>>> f.size
8.5
>>> f.sku
'1234-0'
>>> f.type
'Unspecified'
>>> f.print_size()
'size 8½'
>>> f2 = Footwear('Hightop', 10, '1234-19')
>>> f2.print_size()
'size 10'
>>> print(f)
Sling-back (size 8½)
>>> print(f2)
Hightop (size 10)
>>> f3 = Footwear('Hightop', 10, '1234-19')
>>> f4 = Footwear('Lowtop', 12, '1234-19')
>>> f2 == f3
True
>>> f2 == f4
False
"""
def __init__(self, style, size, sku, shoetype='Unspecified'):
self.style = style
self.size = size
self.sku = sku
self.type = shoetype
def print_size(self):
if int(self.size) == self.size:
return 'size {0}'.format(int(self.size))
return 'size {0}½'.format(int(self.size))
def __str__(self):
return '{0} ({1})'.format(self.style, self.print_size())
def __eq__(self, other):
return self.type == other.type and self.style == other.style and \
self.size == other.size and self.sku == other.sku
class Boot(Footwear):
"""
>>> b = Boot('Hiking', 11.5, '1234-10')
>>> print(b)
Boot - Hiking (size 11½)
"""
def __init__(self, style, size, sku, shoetype='Boot'):
Footwear.__init__(self, style, size, sku, shoetype)
def __str__(self):
return '{0} - {1}'.format(self.type, Footwear.__str__(self))
class Shoe(Footwear):
"""
>>> s = Shoe('Generic', 9.5, '1234-23')
>>> print(s)
Shoe - Generic (size 9½)
"""
def __init__(self, style, size, sku, shoetype='Shoe'):
Footwear.__init__(self, style, size, sku, shoetype)
def __str__(self):
return '{0} - {1}'.format(self.type, Footwear.__str__(self))
class DressShoe(Shoe):
"""
>>> ds = DressShoe('Sling-back', 8.5, '1234-43')
>>> print(ds)
Dress Shoe - Sling-back (size 8½)
"""
def __init__(self, style, size, sku, shoetype='Dress Shoe'):
Shoe.__init__(self, style, size, sku, shoetype)
class CasualShoe(Shoe):
"""
>>> cs = CasualShoe('Moccasin', 12.5, '1234-62')
>>> print(cs)
Casual Shoe - Moccasin (size 12½)
"""
def __init__(self, style, size, sku, shoetype='Casual Shoe'):
Shoe.__init__(self, style, size, sku, shoetype)
if __name__ == '__main__':
import doctest
doctest.testmod()