python的一个小程序,一直死循环,跳不出来,求大神解答!! 10

 我来答
zxszx4
2017-01-19 · TA获得超过511个赞
知道小有建树答主
回答量:732
采纳率:42%
帮助的人:207万
展开全部
你的判断条件没成立吧,while True这个判断后面的if如果判断不正确后续的执行就死循环了,再写个else让判断的两个变量的值能改变到符合条件的可能里就可以了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
天枰非官
2017-01-19 · TA获得超过2455个赞
知道小有建树答主
回答量:1620
采纳率:89%
帮助的人:242万
展开全部
请问能否提供一下文本格式的代码
将printf "I smell a wumpus"移到上一行后
将剩下部分与printf "you are in cave"对齐
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
sdwffzlll
2017-01-19 · TA获得超过758个赞
知道小有建树答主
回答量:498
采纳率:85%
帮助的人:237万
展开全部
from random import choice
import time

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 play this, just type the numbers of the caves tou wish to enter"
print wumpus_location
print player_location
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 next"
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 "Aargj! you got eaten by wumpus!"
break
player_location = choice(cave_numbers)
time.sleep(2)
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式