依然少打很多剧情,并修改了很多,还好,能运行

 #!urs/bin/python
#coding:utf-8 from sys import exit
from random import randint class Game(object): def __init__(self,start):
self.quips = [
"you died.",
"such a luser.",]
self.start = start def play(self):
next = self.start while True:
print "\n------------"
room = getattr(self,next)
next = room() def death(self):
print self.quips[randint(0,len(self.quips)-1)]
exit(1) def central_corridor(self):
print "in #25 planet"
print "we must find weapon" action = raw_input(">>") if action == "shoot":
print "you died .because shoot"
return 'death'
elif action == 'dodge':
print "you head and eats U"
return 'death'
elif action == "joke":
print "lucky!"
return 'laser'
else:
print "DOES"
return 'central_corridor' def laser(self):
print "you get bomb"
code = "%d" % (randint(1,9))
guess= raw_input("enter key:>>")
guesses = 0 while guess != code and guesses <10:
print "BZZZZZZZZZZZZEDDDDDD"
guesses +=1
guess = raw_input("[enter key:]>>") if guess == code:
print "you guess right"
return 'the_bridge'
else:
print "ship go away and you die"
return 'death' def the_bridge(self):
print "which you choise :" action = raw_input(">>") if action == "throw bomb":
print "it bomb lost"
return 'death' elif action == "get bomb":
print "get it .bomb"
return 'escape_pod'
else:
print "go back"
return 'the_bridge' def escape_pod(self):
print "do U take?" good_pod=randint(1,3)
guess = raw_input('[pod]>>') if int(guess) != good_pod:
print "into jam jelly"
return 'death' else:
print "time ,you won!"
exit(0)
a_game = Game("central_corridor")
a_game.play()

Output:

 ------------
in #25 planet
we must find weapon
>>joke
lucky! ------------
you get bomb
enter key:>>3
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>5
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>7
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>9
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>2
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>4
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>6
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>8
you guess right ------------
which you choise :
>>get bomb
get it .bomb ------------
do U take?
[pod]>>2
time ,you won! ***Repl Closed***

Learn Python the hard way, ex42 物以类聚的更多相关文章

  1. 笨办法学 Python (Learn Python The Hard Way)

    最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注 ...

  2. [IT学习]Learn Python the Hard Way (Using Python 3)笨办法学Python3版本

    黑客余弦先生在知道创宇的知道创宇研发技能表v3.1中提到了入门Python的一本好书<Learn Python the Hard Way(英文版链接)>.其中的代码全部是2.7版本. 如果 ...

  3. 学 Python (Learn Python The Hard Way)

    学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注释和井号 习题 ...

  4. 《Learn python the hard way》Exercise 48: Advanced User Input

    这几天有点时间,想学点Python基础,今天看到了<learn python the hard way>的 Ex48,这篇文章主要记录一些工具的安装,以及scan 函数的实现. 首先与Ex ...

  5. 快速入门:十分钟学会PythonTutorial - Learn Python in 10 minutes

    This tutorial is available as a short ebook. The e-book features extra content from follow-up posts ...

  6. Python basic (from learn python the hard the way)

    1. How to run the python file? python ...py 2. UTF-8 is a character encoding, just like ASCII. 3. ro ...

  7. 笨办法学Python(learn python the hard way)--练习程序42

    下面是练习42,基于python3 #ex42.py 1 class TheThing(object): 2 #__init__为class设置内部变量的方式,正常情况下函数内的变量与外部没有关联,但 ...

  8. Learn Python the hard way, ex41 来自Percal 25 号星星的哥顿人

    我承认,我偷懒了,少打了大量代码(剧情),英文太差,下次可以编个中文的试试 #!/urs/bin/python #coding:utf-8 from sys import exit from rand ...

  9. 笨办法学Python(learn python the hard way)--练习程序31-35

    下面是练习31-练习35,基于python3 #ex31.py 1 print("You enter a dark room witn two doors. Do you go throug ...

随机推荐

  1. socket参数的详解

    socket参数的详解 socket.socket(family=AF_INET,type=SOCK_STREAM,proto=0,fileno=None) 创建socket对象的参数说明: fami ...

  2. DevExpress v18.2版本亮点——Analytics Dashboard篇(二)

    行业领先的.NET界面控件——DevExpress v18.2版本亮点详解,本文将介绍了DevExpress Analytics Dashboard v18.2 的版本亮点,新版30天免费试用!点击下 ...

  3. css 上下居中的广法

    方法1 .text{ text-align:center; font-size:0; } .text span{ vertical-align:middle; display:inline-block ...

  4. css3 宽度百分比减去固定宽度 无效问题

    一定要注意中间横线的间距才有效果 正确 width: calc(50% - 10px); 错误 width:calc(50%-10px);

  5. LeetCode--128--最长连续序列(python)

    给定一个未排序的整数数组,找出最长连续序列的长度. 要求算法的时间复杂度为 O(n). 示例: 输入: [100, 4, 200, 1, 3, 2]输出: 4解释: 最长连续序列是 [1, 2, 3, ...

  6. CF1242B. 0-1 MST

    题目大意 有一个n个点的完全图,上面有m条边的权值为1,其余为0 求MST n,m<=10^5 题解 方法一: 维护一个点集,表示当前MST中的点 一开始任意加一个点 对于一个未加入的点,如果和 ...

  7. linux运维、架构之路-HAProxy反向代理

    一.HAProxy介绍          专业反向代理,支持双机热备支持虚拟主机,配置简单,拥有非常不错的服务器健康检查功能,当其代理的后端节点出现故障, HAProxy会自动将该服务器摘除,故障恢复 ...

  8. mysql NOT NULL约束 语法

    mysql NOT NULL约束 语法 作用:约束强制列不接受 NULL 值. 东莞大理石平台 说明:NOT NULL 约束强制字段始终包含值.这意味着,如果不向字段添加值,就无法插入新记录或者更新记 ...

  9. HDU 6153 A Secret ( KMP&&DP || 拓展KMP )

    题意 : 给出两个字符串,现在需要求一个和sum,考虑第二个字符串的所有后缀,每个后缀对于这个sum的贡献是这个后缀在第一个字符串出现的次数*后缀的长度,最后输出的答案应当是 sum % 1e9+7 ...

  10. input 的 type 等于 file

    高版本浏览器由安全问题没法获得文件的绝对路径, 因此使用浏览器自制播放器只能使用其他的手段实现. 使用相对路径, 把浏览器与文件放在同一路径下即可使用.通用性受到限制.