我承认,我偷懒了,少打了大量代码(剧情),英文太差,下次可以编个中文的试试

 #!/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 号星星的哥顿人的更多相关文章

  1. ex41习题 41: 来自 Percal 25 号行星的哥顿人(Gothons)

    ex41习题 41: 来自 Percal 25 号行星的哥顿人(Gothons) 学习到本题卡住了,遇到一点费解的地方,mark一下.本题主要是介绍函数在字典这种数据类型中的应用,本实验在python ...

  2. Learn Python The Hard Way ex41中的程序

    import random from urllib import urlopen import sys WORD_URL = "http://learncodethehardway.org/ ...

  3. learn python the hard way 习题18~25总结

    定义函数和调用函数的语法 定义函数 形式: def functionName(p1,p2): statement other statement 需要注意: 紧跟者函数定义的代码是否使用了4个空格的缩 ...

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

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

  5. 学 Python (Learn Python The Hard Way)

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

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

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

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

    下面是练习41,基于python3 #ex41.py 1 #打印文档字符串 print(函数名.__doc__) 2 from sys import exit 3 from random import ...

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

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

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

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

随机推荐

  1. Linux系统性能测试工具(五)——磁盘io性能工具之fio

    本文介绍关于Linux系统(适用于centos/ubuntu等)的磁盘io性能测试工具-fio.磁盘io性能测试工具包括: fio: dd

  2. 03python面向对象编程之Python中单下划线和双下划线的区别7

    通常Python类中会有_和__的方法,是指什么意思呢?如下: 双下划线表示内部不允许访问,一个下划线表示这样的实例变量外部是可以访问的,但是,按照约定俗成的规定,当你看到这样的变量时,意思就是,“虽 ...

  3. tf模型可视化工具

    一方面可以用tensorboard来可视化,更方便的是用如下网址: https://lutzroeder.github.io/netron/

  4. 为什么我选择用 flutter

    1. flutter 生成的是机器代码,他既不是 hybrid 也不是transpiler,  因此有很高的执行效率. 2. declarative ui,这不是什么新的概念,在 react vue ...

  5. thymeleaf常用模板方法收集

    判断是不是为空1.th:if="${xxx} != null" th:if="${xxx != null}" 是不是为空字符串 1.th:if="${ ...

  6. Django【第17篇】:Django之信号

    django中的信号 Django中的信号及其用法 Django中提供了"信号调度",用于在框架执行操作时解耦. 一些动作发生的时候,系统会根据信号定义的函数执行相应的操作 Dja ...

  7. 交互输入与for语句

    交互输入与for语句 1.   交互输入 read命令可以同时定义多个变量值:输入的内容默认以空格为分隔符,将值输入到对应的变量中:read尽量避免交互 如果默认值过多,最后所有的值会被赋予给最有一个 ...

  8. JavaScript正则表达式简介(一)

    一.正则表达式 正则表达式Regular Expression,可以简写为regexp.regex或是RE. 正则表达式使用单个字符串来描述或是匹配一系列符合某个句法规则的字符串模型. 按照某种规则去 ...

  9. 在Python中,如何将一个字符串数组转换成整型数组

    https://blog.csdn.net/xiangchengguan/article/details/78987041 arr = ['] arr = list(map(int,arr)) pri ...

  10. PHP获取数组最大值下标的方法

    <?php $hots = array('8213'=> 0,'8212'=> 100,'8172'=> 10008); $key = array_search(max($ho ...