【问题标题】:While loop incrementer not functioning properly虽然循环增量器无法正常工作
【发布时间】:2016-07-17 03:18:17
【问题描述】:

现在,我的代码正确地吐出了游戏中的第一个游戏(由 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

【问题讨论】:

    标签: python while-loop iteration increment


    【解决方案1】:

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

    尝试将其更改为:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 2015-08-21
      • 1970-01-01
      • 2019-11-16
      • 1970-01-01
      相关资源
      最近更新 更多