Learn Python the hard way, ex41 来自Percal 25 号星星的哥顿人
我承认,我偷懒了,少打了大量代码(剧情),英文太差,下次可以编个中文的试试
#!/urs/bin/python
#coding:utf-8
from sys import exit
from random import randint def death():
quips=["you died. you kinda suck at this.",
"nice job,you died ...jackass.",
"such a luser",
"I have a small puppy that's better at this."] print quips[randint(0,len(quips)-1)]
exit(1) def central_corridor():
print "the gothons of planet percal #25 have invaded your ship and destroyed"
print "your entire crew. you are the last surviving member and your last"
print "mission is to get the neutron destruct bomb from the weapons armory"
print "put it in the bridge,and blow the ship up after getting into an "
print "escape pod"
print "\n"
print "you're running down the central corrdior to the weapons armory when"
print "a gothon jumps out,red scaly skin ,dark grimy teeth,and evil clown costume"
print "flowing around his hate filled body.he's blocking the door to the"
print "armory and about to pull a weapon to blast you." action =raw_input(">>") if action == "shoot!":
print "quick on the draw you yank out your blaster and fire it at the gothon"
print "his clown costume is flowing and moving around his body,which throws"
return "you are dead.then he eats you." elif action == "dodge!":
print "like a world class boxer you dodge,weave ,slip and slide right"
print "as the gothon's blaster cranks a laser past your head."
return "death" elif action == "tell a joke":
print "lucky for you they made you learn gothon insults in the academy."
print "you tell the one tothon joke you know:"
return "laser_weapon_armory"
else :
print "DOES NOT COMPUTE"
return 'central_corridor' def laser_weapon_armory():
print "you do a dive roll into the weapon armory,crouch and scan the room"
print "for more gothens that might be hiding. it's dead quiet,too quiet"
print 'get the bomb. the code is 3 digits.'
code = "%d%d%d" % (randint(1,9),randint(1,9),randint(1,9))
guess = raw_input("[keypad]>>")
guesses = 0 while guess != code and guesses<10:
print "BZZZZZZZ"
guesses+=1
guess = raw_input("[keypad]>>") if guess == code:
print "bridge where you must place it in the right spot"
return 'the_bridge'
else :
print "ship from their ship and you die"
return 'death' def the_bridge():
print "arm and don't want to set it off." action = raw_input(">>") if action == "throw the bomb":
print "it goes off"
return 'death'
elif action == "slowly place the bomb":
print "get off this tin can"
return 'escape_pod'
else:
print "DOES NOT"
return "the_bridge" def escape_pod():
print "do you take?"
good_pod = randint(1,5)
guess = raw_input("[pod #]>>") if int(guess) != good_pod:
print "into jam jelly"
return 'death'
else:
print "time .you won"
exit(0) ROOMS = {
'death':death,
'central_corridor':central_corridor,
'laser_weapon_armory':laser_weapon_armory,
'the_bridge':the_bridge,
'escape_pod':escape_pod
} def runner(map,start):
next = start while True:
room= map[next]
print "\n-----------"
next = room() runner(ROOMS,'central_corridor')
Output:
-----------
the gothons of planet percal #25 have invaded your ship and destroyed
your entire crew. you are the last surviving member and your last
mission is to get the neutron destruct bomb from the weapons armory
put it in the bridge,and blow the ship up after getting into an
escape pod you're running down the central corrdior to the weapons armory when
a gothon jumps out,red scaly skin ,dark grimy teeth,and evil clown costume
flowing around his hate filled body.he's blocking the door to the
armory and about to pull a weapon to blast you.
>>tell a joke
lucky for you they made you learn gothon insults in the academy.
you tell the one tothon joke you know: -----------
you do a dive roll into the weapon armory,crouch and scan the room
for more gothens that might be hiding. it's dead quiet,too quiet
get the bomb. the code is 3 digits.
[keypad]>>123
BZZZZZZZ
[keypad]>>369
BZZZZZZZ
[keypad]>>789
BZZZZZZZ
[keypad]>>741
BZZZZZZZ
[keypad]>>456
BZZZZZZZ
[keypad]>>951
BZZZZZZZ
[keypad]>>753
BZZZZZZZ
[keypad]>>852
BZZZZZZZ
[keypad]>>147
BZZZZZZZ
[keypad]>>963
BZZZZZZZ
[keypad]>>563
ship from their ship and you die -----------
such a luser ***Repl Closed***
Learn Python the hard way, ex41 来自Percal 25 号星星的哥顿人的更多相关文章
- ex41习题 41: 来自 Percal 25 号行星的哥顿人(Gothons)
ex41习题 41: 来自 Percal 25 号行星的哥顿人(Gothons) 学习到本题卡住了,遇到一点费解的地方,mark一下.本题主要是介绍函数在字典这种数据类型中的应用,本实验在python ...
- Learn Python The Hard Way ex41中的程序
import random from urllib import urlopen import sys WORD_URL = "http://learncodethehardway.org/ ...
- learn python the hard way 习题18~25总结
定义函数和调用函数的语法 定义函数 形式: def functionName(p1,p2): statement other statement 需要注意: 紧跟者函数定义的代码是否使用了4个空格的缩 ...
- 笨办法学 Python (Learn Python The Hard Way)
最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注 ...
- 学 Python (Learn Python The Hard Way)
学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注释和井号 习题 ...
- [IT学习]Learn Python the Hard Way (Using Python 3)笨办法学Python3版本
黑客余弦先生在知道创宇的知道创宇研发技能表v3.1中提到了入门Python的一本好书<Learn Python the Hard Way(英文版链接)>.其中的代码全部是2.7版本. 如果 ...
- 笨办法学Python(learn python the hard way)--练习程序41
下面是练习41,基于python3 #ex41.py 1 #打印文档字符串 print(函数名.__doc__) 2 from sys import exit 3 from random import ...
- 《Learn python the hard way》Exercise 48: Advanced User Input
这几天有点时间,想学点Python基础,今天看到了<learn python the hard way>的 Ex48,这篇文章主要记录一些工具的安装,以及scan 函数的实现. 首先与Ex ...
- 笨办法学Python(learn python the hard way)--练习程序42
下面是练习42,基于python3 #ex42.py 1 class TheThing(object): 2 #__init__为class设置内部变量的方式,正常情况下函数内的变量与外部没有关联,但 ...
随机推荐
- R语言 绘图——条形图可以将堆积条形图与百分比堆积条形图配合使用
在使用堆积条形图时候,新增一个百分比堆积条形图,可以加深读者印象. 封装一个function函数后只需要在调用的数据上改一下pos=‘fill’的代码即可.比较方便. 案例: # 封装函数 fun1& ...
- 关于Mysql 修改密码的记录
初次安装后完毕,使用管理员身份进入cmd界面, 输入" mysql -u root -p",出现"Enter password:",直接回车输入" s ...
- Shell编程变量
shell变量 什么是变量,存放了各种数据,在linux怎么定义了变量,name=ken,name就是变量名,ken就是变量值, 但是在shell中,有三种方式: name=ken name='ken ...
- Python自动化学习--批量执行.py用例
这段时间在摸索自动化,学到执行测试用例的时候发现,执行单用例的时候很简单,如果想多条用例执行的话就没那么简单了,经过几番查找,找到如下方法: unittest模块中的TestLoader类有一个dis ...
- 09java进阶——IO
1.File类 1.1目录及路径分隔符 package cn.jxufe.java.chapter09.demo01; import java.io.File; public class Test01 ...
- 深度强化学习(Deep Reinforcement Learning)入门:RL base & DQN-DDPG-A3C introduction
转自https://zhuanlan.zhihu.com/p/25239682 过去的一段时间在深度强化学习领域投入了不少精力,工作中也在应用DRL解决业务问题.子曰:温故而知新,在进一步深入研究和应 ...
- MixConv
深度分离卷积一般使用的是3*3的卷积核,这篇论文在深度分离卷积时使用了多种卷积核,并验证了其有效性 1.大的卷积核能提高模型的准确性,但也不是越大越好.如下,k=9时,精度逐渐降低 2. mixCon ...
- Kettle整理
下载kettle版本 (1)hadoop version 查看hadoop的版本 hadoop2.6 (2)则在data-integration\plugins\pentaho-big-data ...
- uoj207 共价大爷游长沙 子树信息 LCT + 随机化 + 路径覆盖
题目传送门 http://uoj.ac/problem/207 题解 如果是一棵静态的树,有一个非常容易想到的算法:统计一下目前的每一个条边被几条路径经过,如果 \(x\) 到 \(y\) 的边的这个 ...
- [CF434D Div1] Tree
问题描述 给定一颗 n 个点的树,树边带权,试求一个排列 P,使下式的值最大 \[ \sum_{i=1}^{n-1}maxflow(P_i,P_{i+1}) \] 其中 maxflow(s, t) 表 ...