def getLotteryGame():不会返回(True)

时间:2014-01-04 23:18:59

标签: python

在我的def getLotteryGame()中:假设检查计时器是否用完,如果是,它会对玩家进行排序,对其进行排名,为他们提供奖金并为他们存储注释,然后返回True并返回True真的,机器人重新加载游戏进行新一轮。我尝试了几种尝试让它返回True的方法。这是代码:

def getLotteryGame():
    global pot
    global players
    different = float(time.time() - lotteryStart)
    years = int(different / Point.YEAR)
    days = int((different % Point.YEAR) / Point.DAY)
    hours = int((different % Point.DAY) / Point.HOUR)
    mins = int((different % Point.HOUR) / Point.MINUTE)
    secs = int(different % Point.MINUTE)
    if secs <= 0:
        if len(players) > 0:
            random.shuffle(players)
            ratios = []
            for i in range(-2, len(players) - 2) if i > 0 else range(len(players)):
                if i < 0:
                    ratios.append(1 - (i * 0.33)) # ratio > 1
                else:
                    ratios.append(1 / (1 + (i * 0.33))) # ratio <= 1
                    winnings = [pot * r for r in ratios]
                for m in range(1, len(players)):
                    notes.store("~lottery~", players[m], "The system has placed you "+Point.ordinal(m)+" in the lottery. The lottery awarded you "+winnings+" P$", time.time())
                    alerts.append(players[m])
                    winnings = int(winnings)
                    point = Point.dPoint[players[m]]
                    point = int(point)
                    point = int(point+winnings)
                    Point.dPoint[players[m]] = int(point)
            return(True)
        elif len(players) == 0:
            return(True)
    else:
         return(False)

当我等待差值为&lt; = 0时,如果secs&lt; = 0.它会继续返回False,而我不确定原因。

2 个答案:

答案 0 :(得分:2)

您的代码逻辑已经破产。代码首次运行时定义lotteryStarttime.time()。稍后,您会找到自lotteryStart以来的秒数。这个秒数偶尔可能为零,并且永远不会小于零。随着时间的推移,它应该始终是积极的。因此,您的代码始终执行返回False的最终else语句。

答案 1 :(得分:1)

different = float(time.time() - lotteryStart)

也许lotteryStart是一个全局变量,而且它没有在任何地方定义?