0
我想輸入玩家的姓名到我的陣列中。我將數組設置爲空,現在我將如何將用戶給出的名稱放入數組中?如何用數組中的字符串替換空值(python)?
1.Here是我到目前爲止編碼:
def randName(team_names):
team_names = list(team_names)
shuffle(team_names)
leftover = team_names.pop() if len(team_names) % 2 else None
trick = [iter(team_names)] * 2
pairs = list(zip(*trick))
return pairs, leftover
teamNames = []
name = ""
while name != "end":
name = raw_input ("Enter the name of an opponent: (end to exit)")
teamNames.append(name)
teamNames.pop()
chart = np.empty((len(teamNames)/2,2), dtype=np.str)
print chart
該代碼以什麼方式沒有做你想要的,你怎麼知道? –
你能詳細說明一下嗎?是不是'teamNames.append(name)'做你剛剛描述的內容? – drum
這是你的整個代碼?定義了「雙」的位置在哪裏? – Kevin