Python Point.py打印但停止打印

Python Point.py打印但停止打印,python,Python,好了,这件事我差不多做完了。所以我被卡在了一个双循环上,它在打印(赢款)后不会打印,所以有些不对劲,但我不确定出了什么问题,但下面是代码。而且它并没有为一名玩家存储备忘、提醒或积分。如果有人能帮助我,我将不胜感激 winnings = [] for n in range(len(ratios)): winnings.append(pot*ratios[n]) print(winnings) #STOPS HERE for winning in win

好了,这件事我差不多做完了。所以我被卡在了一个双循环上,它在打印(赢款)后不会打印,所以有些不对劲,但我不确定出了什么问题,但下面是代码。而且它并没有为一名玩家存储备忘、提醒或积分。如果有人能帮助我,我将不胜感激

    winnings = [] 
    for n in range(len(ratios)):
      winnings.append(pot*ratios[n])
    print(winnings) #STOPS HERE
    for winning in winnings[1:]:
      # loop over all but the first element in winnings
      winning = int(winning)
      for i, player in enumerate(players[1:]):
        # loop over all but the first player, adding indices
        notes.store("~lottery~", player, "The system has placed you %s in the lottery. The lottery awarded you %s P$" % (Point.ordinal(i), winning), time.time())
        alerts.append(player)
        point = Point.dPoint[player] + winning
        Point.dPoint[player] = point
    return True
  elif len(players) == 0:

如果
winnings
是长度为1的列表,则范围(1,len(winnings))中o的
循环将不执行循环体,因为范围为空:

>>> list(range(1, 1))
[]
如果不想跳过第一个元素,请不要从
1
开始,而是从
0
循环:

>>> range(0, 1)
[0]
Python索引是基于0的

注意,在Python中,通常直接循环列表,而不是生成索引,然后生成索引。即使您仍然需要循环索引,也可以使用
enumerate()
函数为您添加循环索引:

winnings = [pot * ratio for ratio in ratios]
for winning in winnings[1:]:
    # loop over all but the first element in winnings
    winning = int(winning)
    for i, player in enumerate(players[1:]):
        # loop over all but the first player, adding indices
        notes.store("~lottery~", player, 
            "The system has placed you {} in the lottery. The lottery awarded "
            "you {} P$".format(Point.ordinal(i), winning), time.time())
        alerts.append(player)
        Point.dPoint[player] += winning
如果需要将所有赢款与所有玩家配对,请使用
zip()


winnings
可能是一个长度为1的列表吗?当我测试它时,winnings列表中只有一个东西,所以是的。啊,如果它是一个或多个列表,我该如何使它工作呢?@user3103923:那么,在这种情况下,你预计会发生什么?为什么你要把指数从1循环到最后一个,而不是从0循环到最后一个?对于循环中的玩家部分,我需要从1开始,而不是从0开始。当然,但是你要从1开始
赢款。如果这不是计划,那么就不要这样做。:-)好吧,我想从1开始,带着奖金和球员。
winnings = [pot * ratio for ratio in ratios]
for i, (winning, player) in enumerate(zip(winnings, players)):
    winning = int(winning)
    notes.store("~lottery~", player, 
        "The system has placed you {} in the lottery. The lottery awarded "
        "you {} P$".format(Point.ordinal(i), winning), time.time())
    alerts.append(player)
    Point.dPoint[player] += winning