首页 > 代码库 > 吃午饭前,按书上的代码写会儿--Hunt the Wumpus第一个版本
吃午饭前,按书上的代码写会儿--Hunt the Wumpus第一个版本
有空就要慢慢练起~~~~脑袋动起来是很快乐的事儿。。。。:)
《易学PYTHON》演练一遍。
from random import choicecave_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, 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 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
吃午饭前,按书上的代码写会儿--Hunt the Wumpus第一个版本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。