Python 达到分数限制时程序未终止?
作为我的第一个python项目,我正在开发一个简单的基于文本的琐事游戏,一旦达到分数限制,我的程序就不会终止Python 达到分数限制时程序未终止?,python,Python,作为我的第一个python项目,我正在开发一个简单的基于文本的琐事游戏,一旦达到分数限制,我的程序就不会终止 def game(quest_list): points = 0 score_limit = 20 x, y = info() time.sleep(2) if y >= 18 and y < 100: time.sleep(1) while points < score_limit:
def game(quest_list):
points = 0
score_limit = 20
x, y = info()
time.sleep(2)
if y >= 18 and y < 100:
time.sleep(1)
while points < score_limit:
random.choice(quest_list)(points)
time.sleep(2)
print("Current score:", points, "points")
print("You beat the game!")
quit()
...
def游戏(任务列表):
分数=0
分数限制=20
x、 y=info()
时间。睡眠(2)
如果y>=18且y<100:
时间。睡眠(1)
当分数低于分数限制时:
随机选择(任务列表)(点数)
时间。睡眠(2)
打印(“当前分数:,分数,分数”)
打印(“你赢了游戏!”)
退出
...
看起来点
变量没有增加。类似的内容可能会在您的内部循环中起作用:
while points < score_limit:
points = random.choice(quest_list)(points)
time.sleep(2)
print("Current score:", points, "points")
除非
points
是可变的数据结构,否则它不会更改值。您可以在中阅读更多关于这方面的信息 点
永远不会递增,因此循环永远不会终止
quest = random.choice(quest_list)
points += quest()