虽然循环增量器不能正常工作

时间:2016-07-17 03:18:18

标签: python while-loop iteration increment

现在,我的代码正确地在游戏中吐出第一个游戏(由start_id标识)。我试图在底部两行增加,但while循环似乎没有读到我正在递增的事实。因此,使用start_id 800和end_id 802的输入只是来自800的信息,出于某种原因。

我是否正确使用增量器?我应该在其他地方初始化i或start_id吗?

games = console(start_id, end_id)
final_output = []

while start_id < (end_id + 1):
    single_game = []
    i = 0
    game_id = games[i][0] 
    time_entries = games[i][1][2][0]
    play_entries = games[i][1][2][1]
    score_entries = games[i][1][2][2]
    team_entries = games[i][1][2][3]
    bovada = games[i][1][0][0][0]
    at_capacity = games[i][1][0][1]
    idisagree_yetrespect_thatcall = games[i][1][0][2][0]
    imsailingaway = games[i][1][1][0][0]
    homeiswheretheheartis = games[i][1][1][1][0]

    zipper = zip(time_entries, play_entries, score_entries, team_entries)

    for play_by_play in zipper:
        single_game.append(game_id)
        single_game.append(play_by_play)
        single_game.append(bovada)
        single_game.append(at_capacity)
        single_game.append(idisagree_yetrespect_thatcall)
        single_game.append(imsailingaway)
        single_game.append(homeiswheretheheartis)

    start_id += 1
    i += 1
    final_output.append(single_game)
return final_output

1 个答案:

答案 0 :(得分:0)

您的问题是您在i循环内初始化增量while,因此每次循环迭代i重置为零。

尝试将其更改为:

i = 0
while start_id < (end_id + 1):
    ...