码迷,mamicode.com
首页 > 其他好文 > 详细

吃午饭前,按书上的代码写会儿--Hunt the Wumpus第一个版本

时间:2014-09-20 15:15:27      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   2014   div   sp   

有空就要慢慢练起~~~~脑袋动起来是很快乐的事儿。。。。:)

《易学PYTHON》演练一遍。

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 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

bubuko.com,布布扣

吃午饭前,按书上的代码写会儿--Hunt the Wumpus第一个版本

标签:style   blog   http   color   io   ar   2014   div   sp   

原文地址:http://www.cnblogs.com/aguncn/p/3983122.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!