LPANDJY
LPANDJY
采纳率0%
2019-01-31 11:28 阅读 818

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

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条回答 默认 最新

  • general1988 Torvalz 2019-01-31 14:25

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

    点赞 评论 复制链接分享