在我的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,而我不确定原因。
答案 0 :(得分:2)
您的代码逻辑已经破产。代码首次运行时定义lotteryStart
,time.time()
。稍后,您会找到自lotteryStart
以来的秒数。这个秒数偶尔可能为零,并且永远不会小于零。随着时间的推移,它应该始终是积极的。因此,您的代码始终执行返回False的最终else
语句。
答案 1 :(得分:1)
different = float(time.time() - lotteryStart)
也许lotteryStart是一个全局变量,而且它没有在任何地方定义?