python的一个小程序,一直死循环,跳不出来,求大神解答!! 10
展开全部
你的判断条件没成立吧,while True这个判断后面的if如果判断不正确后续的执行就死循环了,再写个else让判断的两个变量的值能改变到符合条件的可能里就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请问能否提供一下文本格式的代码
将printf "I smell a wumpus"移到上一行后
将剩下部分与printf "you are in cave"对齐
将printf "I smell a wumpus"移到上一行后
将剩下部分与printf "you are in cave"对齐
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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)
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)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询