简体   繁体   English

While循环增量器无法正常运行

[英]While loop incrementer not functioning properly

Right now, my code is correctly spitting out the first game (identified by start_id) in games. 现在,我的代码正确地吐出了游戏中的第一个游戏(由start_id标识)。 I am trying to increment in the bottom two lines, but the while loop doesn't seem to read the fact that I'm incrementing. 我试图在最下面两行进行递增,但是while循环似乎并未读取我正在递增的事实。 So the input of this with start_id 800 and end_id 802 is just the information from 800, for some reason. 因此,出于某种原因,使用start_id 800和end_id 802进行的输入只是来自800的信息。

Am I using the incrementers correctly? 我是否正确使用增量器? Should I be initializing one of i or start_id elsewhere? 我应该在其他地方初始化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

Your problem is that you initialize the increment-er i inside the while loop so every time your loop iterates i is reset to zero. 您的问题是,您在while循环中初始化了递增运算符i while因此每次循环迭代i都会重置为零。

Try changing it to: 尝试将其更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM