回答編集履歴
1
a
answer
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
self.win = 0
|
12
12
|
self.lose = 0
|
13
13
|
self.draw = 0
|
14
|
-
|
14
|
+
|
15
15
|
def get_winrate(self):
|
16
16
|
return self.win / (self.lose + self.lose + self.draw)
|
17
17
|
|
@@ -47,21 +47,26 @@
|
|
47
47
|
Swallows.draw = 2
|
48
48
|
|
49
49
|
teams = [Carp, Tigers, BayStars, Giants, Dragons, Swallows]
|
50
|
+
|
51
|
+
# header
|
52
|
+
print('{:10s} {:3s} {:4s} {:4s} {:6s}'.format(
|
53
|
+
'team', 'win', 'lose', 'draw', 'rate'))
|
50
54
|
for team in teams:
|
51
55
|
winrate = team.get_winrate()
|
52
|
-
print(f'{team.name:10s} {team.win:3d} {team.lose:
|
56
|
+
print(f'{team.name:<10s} {team.win:<3d} {team.lose:<4d} {team.draw:<4d} {winrate:<6.2%}')
|
53
57
|
# Python 3.6 以前なら format() を使う。
|
54
|
-
# print('{0.name:10s} {0.win:3d} {0.lose:3d} {0.draw:3d} {1:.2%}'.format(
|
58
|
+
# print('{0.name:10s} {0.win:3d} {0.lose:3d} {0.draw:3d} {1:5.2%}'.format(
|
55
59
|
# team, team.get_winrate()))
|
56
60
|
```
|
57
61
|
|
58
62
|
## 出力
|
59
63
|
|
60
64
|
```
|
65
|
+
team win lose draw rate
|
61
|
-
Carp
|
66
|
+
Carp 88 51 4 83.02%
|
62
|
-
Tigers
|
67
|
+
Tigers 78 61 4 61.90%
|
63
|
-
BayStars
|
68
|
+
BayStars 73 65 5 54.07%
|
64
|
-
Giants
|
69
|
+
Giants 72 68 3 51.80%
|
65
|
-
Dragons
|
70
|
+
Dragons 59 79 5 36.20%
|
66
|
-
Swallows
|
71
|
+
Swallows 45 96 2 23.20%
|
67
72
|
```
|