□アウトプット
team win lose draw rate
のように表示させたいですが、記載方法がわかりません。どのようにおこなえばよろしいでしょうか。
print(f"{team:8s} {win:3d} {lose:3d} {draw:3d} {rate:3f}")
ーーーーーーーーーーーーーーーーーーーーーーーー
from baseball_team import Baseball_Team
list = []
Carp = Baseball_Team("Carp")
Tigers = Baseball_Team("Tigers")
BayStars = Baseball_Team("BayStars")
Giants = Baseball_Team("Giants")
Dragons = Baseball_Team("Dragons")
Swallows = Baseball_Team("Swallows")
Carp.name = "Carp"
Carp.win = 88
Carp.lose = 51
Carp.draw = 4
Tigers.name = "Tigers"
Tigers.win = 78
Tigers.lose = 61
Tigers.draw = 4
BayStars.name = "BayStars"
BayStars.win = 73
BayStars.lose = 65
BayStars.draw = 5
Giants.name = "Giants"
Giants.win = 72
Giants.lose = 68
Giants.draw = 3
Dragons.name = "Dragons"
Dragons.win = 59
Dragons.lose = 79
Dragons.draw = 5
Swallows.name = "Swallows"
Swallows.win = 45
Swallows.lose = 96
Swallows.draw = 2
Carp.calc_win_rate()
Tigers.calc_win_rate()
BayStars.calc_win_rate()
Giants.calc_win_rate()
Dragons.calc_win_rate()
Swallows.calc_win_rate()
print(f"{team:8s} {win:3d} {lose:3d} {draw:3d} {rate:3f}")
print(f"{Carp.name:8s} {Carp.win:3d} {Carp.lose:3d} {Carp.draw:3d} {Carp.rate:.3f}")
print(f"{Tigers.name:8s} {Tigers.win:3d} {Tigers.lose:3d} {Tigers.draw:3d} {Tigers.rate:.3f}")
print(f"{BayStars.name:8s} {BayStars.win:3d} {BayStars.lose:3d} {BayStars.draw:3d} {BayStars.rate:.3f}")
print(f"{Giants.name:8s} {Giants.win:3d} {Giants.lose:3d} {Giants.draw:3d} {Giants.rate:.3f}")
print(f"{Dragons.name:8s} {Dragons.win:3d} {Dragons.lose:3d} {Dragons.draw:3d} {Dragons.rate:.3f}")
print(f"{Swallows.name:8s} {Swallows.win:3d} {Swallows.lose:3d} {Swallows.draw:3d} {Swallows.rate:.3f}")
ーーーーーーーーーーーーーーーーー
ec2-user:~/environment $ python exec_baseball_team.py
team win lose draw rate
Carp 88 51 4 0.633
Tigers 78 61 4 0.561
BayStars 73 65 5 0.529
Giants 72 68 3 0.514
Dragons 59 79 5 0.428
Swallows 45 96 2 0.319
回答2件
あなたの回答
tips
プレビュー