因此,我的老師希望我使用兩個函數製作一個程序,將「名人堂」添加到列表中的每個棒球選手。我們應該開始用這個程序打印每個名單上球員的名字:使用函數將一個字符串添加到列表中的每個項目上
def show_players(players):
"""Show list of baseball players"""
for player in players:
print(player.title())
baseball_players = ['jackie robinson', 'babe ruth', 'barry bonds']
show_players(baseball_players)
我們必須寫另一個功能,增加了「名人堂成員」到每一個運動員,這是我已經得到了(它不工作,我怎麼想):
def show_players(players):
"""Show list of baseball players"""
for player in players:
print(player.title())
def make_HOF(baseball_players):
"""Make each baseball player a Hall of Famer"""
HOF = "Hall of Famer "
for player in baseball_players:
HOF_players = [HOF + player]
return HOF_players
HOF_players = []
baseball_players = ['jackie robinson', 'babe ruth', 'barry bonds']
make_HOF(baseball_players)
show_players(HOF_players)
[String Concatenation and Formatting](http://www.pythonforbeginners.com/concatenation/string-concatenation-and-formatting-in-python) – Rafael