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设置内部变量的方式,正常情况下函数内的变量与外部没有关联,但 ...
随机推荐
- JSP页面包含其他页面的三种方式及区别
一. <%@ include file="header.inc"%> 该指令在编译之前先读入指定的页面中的内容(并不对动态内容求值),融合后的完整页面再被整体的转换为一 ...
- 使用Docker搭建Jumpserver堡垒机
使用Docker搭建Jumpserver堡垒机 1.环境准备 操作系统:CentOS 7.6.1810 软件源:阿里云镜像 #内核版本(Docker 要求 CentOS 系统的内核版本高于 3.10) ...
- java封装小实例
封装是java语言的一个重要的特性,通过把对象的属性和操作方法封装在同一个类中,对外只提供公共方法对这些数据进行set和get,同时封装也能对方法进行封装.总之封装能够有效地隐藏内部的代码细节,从而使 ...
- CodeBlocks17.12+汉化包下载及用法
本文已迁移至:https://blog.csdn.net/COCO56/article/details/95228780
- 图解Qt安装(Windows平台)
http://c.biancheng.net/view/3858.html 本节介绍 Qt 5.9.0 在 Windows 平台下的安装,请提前下载好 Qt 5.9.0.不知道如何下载 Qt 的读者请 ...
- centOS7 通过nmtui和nmcli图形配置网络服务
一.通过nmtui配置网络参数 Linux系统配置网络参数的方式有很多种,其中最简单最直接的方式就是直接修改网卡配置文件,但这种方式也很容易出错,比如说IPADDR.NETMASK.GATEWAY等参 ...
- 牛客练习赛33 E tokitsukaze and Similar String (字符串哈希hash)
链接:https://ac.nowcoder.com/acm/contest/308/E 来源:牛客网 tokitsukaze and Similar String 时间限制:C/C++ 2秒,其他语 ...
- 10年前文章_ vi编辑器查找与替换方法
vi编辑器查找与替换方法1.查找:/ 当前行往下找:? 当前行往上找找到后继续查找同方向 n反方向 N2.替换格式: range s/source/target/g解释:range表示要搜索的范围 & ...
- python中strftime和strptime函数
strftime和strptime函数均来自包datetime from datetime import * strftime: 将datetime包中的datetime类,按照入参格式生成字符串变量 ...
- Codeforces 980D
这题其实挺水的,但我比较vegetable,交了好多次才过. 题意: 给定一个序列,把这个序列的所有连续子序列分组,每组中任意两个数相乘是个完全平方数,输出每个子序列最少分的组数: 思路: 先把每个数 ...