LPANDJY 2019-01-31 11:28 采纳率: 0%
浏览 847

代码运行总是重复的问题。

from random import choice

cave_numbers = range(1,21)
wumpus_location = choice(cave_numbers)
player_location = choice(cave_numbers)
while player_location == wumpus_location:
player_location = choice(cave_numbers)

print "Welcome to Hunt the Wumpus!"
print "You can see", len(cave_numbers), "caves"
print "To playm just type the number"
print "of the cave you wish to enter next"

while True:
print "You are in cave", player_location
if (player_location == wumpus_location -1 or
player_location == wumpus_location +1):
print "I smell a wumpus!"
print "Which cave nuxt?"
player_input = raw_input(">")
if (not player_input,isdigit() or
int(player_input) not in cave_numbers):
print player_input, "is not a cave!"
else:
player_location = int(player_input)
if player_location == wumpus_location:
print "Aargh! You got eatenby a wumpus!"
break
这串代码为什么运行起来总是重复?求

  • 写回答

1条回答

  • Torvalz 2019-01-31 14:25
    关注

    while语句一直为真,没有中断跳出的触发条件或场景,所以这个会一直循环执行

    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法