学习python第一天
学习python第一天 :
下了个编辑器notepad++ 结果不知道如何运行 上网上找了一下 在运行之后的对话框加cmd /k python "$(FULL_CURRENT_PATH)" & ECHO. & PAUSE & EXIT
之后能够成功的运行了 写了一个小游戏的代码 如下:
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 Hurt the Wumpus!"
print"You can see",len(cave_numbers),"caves"
print"To play,just tyoe 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 cave"
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"Aargh!You got eaten by a wumpus!"
break
第一次运行的时候显示
NameError: name is not defined 之后缩进了一下好了
第二次运行的时候显示
NameError: name 'ture' is not defined 结果发现是自己单词打错了
之后发现整个代码无限循环 You are in cave X 也没在网上找到什么办法 代码也没有问题
之后把与倒数第二行的break改成与while 对齐 是不循环了 但是没办法打字
进入运行的界面 有时候是请安任意键继续 有的时候是有个>>>输入 输入个数字之后又是请按任意键继续 到现在也没什么办法
准备上网问问 2016 5 9 10.13

浙公网安备 33010602011771号