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设置内部变量的方式,正常情况下函数内的变量与外部没有关联,但 ...
随机推荐
- 56. Merge Intervals (JAVA)
Given a collection of intervals, merge all overlapping intervals. Example 1: Input: [[1,3],[2,6],[8, ...
- 内存缓存的使用Demo
使用缓存的目的是为了使用的应用程序能更快速的响应用户输入,是程序高效的运行.有时候我们需要将远程web服务器获取的数据缓存起来,减少对同一个url多次请求. 内存缓存我们可以使用sdk中的NSURLC ...
- 204-基于Xilinx Virtex-6 XC6VLX240T 和TI DSP TMS320C6678的信号处理板
基于Xilinx Virtex-6 XC6VLX240T 和TI DSP TMS320C6678的信号处理板 1.板卡概述 板卡由我公司自主研发,基于VPX架构,主体芯片为两片 TI DSP TMS ...
- 2019 计蒜之道 初赛 第二场 B. 百度AI小课堂-上升子序列(简单) ( 实现)
题目背景 91029102 年 99 月 22 日,百度在 X 市 XX 中学举办的第一场 AI 知识小课堂大获好评!同学们对矩阵的掌握非常棒. 今天的 AI 知识小课堂的第二场开讲啦.本场 AI ...
- Laravel——缓存使用
1.使用Redis类 use Illuminate\Support\Facades\Redis; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...
- Django【第7篇】:Django之ORM跨表操作(聚合查询,分组查询,F和Q查询等)
django之跨表查询及添加记录 一:创建表 书籍模型: 书籍有书名和出版日期,一本书可能会有多个作者,一个作者也可以写多本书,所以作者和书籍的关系就是多对多的关联关系(many-to-many); ...
- java实现队列和栈
队列:队列其实就是我们生活中的排队现象,先进入的先出,后进入的后出,代码实现如下: public class Queue<E> { private int front;//队头一端,只允许 ...
- 阅读《Effective Java》每条tips的理解和总结(2)(持续更新)
15. 使类和成员的可访问性最小化 一个好用的类的属性必须要隐藏起来,干净的将它与类的api分离开来,类之间只通过api相互使用,降低他们之间的耦合性.为了做到这一点,建议根据情况选择尽可能低的访问级 ...
- 基于http方式搭建YUM源服务器
基于http方式搭建YUM源服务器 (2012-09-21 11:59:14) 转载▼ 标签: yum linux lnmp lamp http 分类: Linux 为了方便公司80多台Linux服务 ...
- mybatis多个参数时传参方式
第一种方案 DAO层的函数方法 Lecture getLecture(Integer id, Integer parentId); 对应的mapper.xml <select id=" ...