笨办法学Python(learn python the hard way)--练习程序41
下面是练习41,基于python3
#ex41.py
1 #打印文档字符串 print(函数名.__doc__)
2 from sys import exit
3 from random import randint
4
5 def death():
6 quips = ["You died. You kinda suck at this.",
7 "Nice job, you died ...jackass.",
8 "Such a luser.",
9 "I have a small puppy that's better at this."]
10
11 print(quips[randint(0, len(quips)-1)])
12 exit(1)
13
14
15 def central_corridor():
16
17 print("The Gothons of Planet Percal #25 have invaded your ship and destroyed")
18 print("your entire crew. You are the last surviving member and your last")
19 print("mission is to get the neutron destruct bomb from the Weapons Armory,")
20 print("put it in the bridge, and blow the ship up after getting into an ")
21 print("escape pod.")
22 print("\n")
23 print("You're running down the central corridor to the Weapons Armory when")
24 print("a Gothon jumps out, red scaly skin, dark grimy teeth,and evil clown costume")
25 print("flowing around his hate filled body. He's blocking the door to the")
26 print("Armory and about to pull a weapon to blast you.")
27
28 action = input("> ")
29
30 if action == "shoot!":
31 print("Quick on the draw you yank out your blaster and fire it at the Gothon.")
32 print("His clown costume is flowing and moving around his body, which throws")
33 print("off your aim. Your laser hits his costume but misses him entirely. This")
34 print("completely ruins his brand new costume his mother bought him, which")
35 print("makes him fly into an insane rage and blast you repeatedly in the face until")
36 print("you are dead, Then he eats you.")
37 return 'death'
38
39 elif action == "dodge!":
40 print("Like a world class boxer you dodge, weave, slip and slide right")
41 print("as the Gothon's blaster cranks a laser past your head.")
42 print("In the middle of your artful dodge your foot slips and you")
43 print("bang your head on the metal wall and pass out.")
44 print("You wake up shortly after only to die as the Gothon stomps on")
45 print("your head and eats you.")
46 return 'death'
47
48 elif action == "tell a joke":
49 print("Lucky for you they made you learn Gothon insults in the academy.")
50 print("You tell the one Gothon joke you know:")
51 print("Lbhe zbgure vf fb sng, jura fur fvgf nebhaq gur ubhfr, fur fvgf nebhaq gur ubhfr.")
52 print("The Gothon stops, tries not to laugh, then busts out laughing and can't move.")
53 print("While he's laughing you run up and shoot him square in the head")
54 print("putting him down, then jump through the Weapon Armory door.")
55 return 'laser_weapon_armory'
56 else:
57 print("DOES NOT COMPUTE!")
58 return 'central_corridor'
59
60 def laser_weapon_armory():
61 print("You do a dive roll into the Weapon Armory, crouch and scan the room")
62 print("for more Gothons that might be hiding. It's dead quiet, too quiet.")
63 print("You stand up and run to the far side of the room and find the")
64 print("neutron bomb in its container. There's a keypad lock on the box")
65 print("and you need the code to get the bomb out. If you get the code")
66 print("wrong 10 times then the lock closes forever and you can't")
67 print("get the bomb. The code is 3 digits.")
68 code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
69 guess = input("[keypad]> ")
70 guesses = 0
71
72 while guess != code and guesses < 10:
73 print("BZZZZEDDD!")
74 guesses += 1
75 guess = input("[keypad]> ")
76 if guess == code:
77 print("The container clicks open and the seal breaks, letting gas out.")
78 print("You grab the neutron bomb and run as fast as you can to the")
79 print("bridge where you must place it in the right spot.")
80 return 'the_bridge'
81 else:
82 print("The lock buzzes one last time and then you hear a sickening")
83 print("melting sound as the mechanism is fused together.")
84 print("You decide to sit there, and finally the Gothons blow up the")
85 print("ship from their ship and you die.")
86 return 'death'
87
88
89 def the_bridge():
90 print("You burst onto the Bridge with the neutron destruct bomb")
91 print("under your arm and surprise 5 Gothons who are trying to")
92 print("take control of the ship. Each of them has an even uglier")
93 print("clown costume than the last. They haven't pulled their")
94 print("weapons out yet, as they see the active bomb under your")
95 print("arm and don't want to set it off.")
96
97 action = input("> ")
98
99 if action == "throw the bomb":
100 print("In a panic you throw the bomb at the group of Gothons")
101 print("and make a leap for the door. Right as you drop it a")
102 print("Gothon shoots you right in the back killing you.")
103 print("As you die you see another Gothon frantically try to disarm")
104 print("the bomb. You die knowing they will probably blow up when")
105 print("it goes off.")
106 return 'death'
107
108 elif action == "slowly place the bomb":
109 print("You point your blaster at the bomb under your arm")
110 print("and the Gothons put their hands up and start to sweat.")
111 print("You inch backward to the door, open it, and then carefully")
112 print("place the bomb on the floor, pointing your blaster at it.")
113 print("You then jump back through the door, punch the close button")
114 print("and blast the lock so the Gothons can't get out.")
115 print("Now that the bomb is placed you run to the escape pod to")
116 print("get off this tin can.")
117 return 'escape_pod'
118
119 else:
120 print("DOES NOT COMPUTE!")
121 return "the_bridge"
122
123
124 def escape_pod():
125 print("You rush through the ship desperately trying to make it to")
126 print("the escape pod before the whole ship explodes. It seems like")
127 print("hardly any Gothons are on the ship, so your run is clear of")
128 print("interference. You get to the chamber with the escape pods, and")
129 print("now need to pick one to take. Some of them could be damaged")
130 print("but you don't have time to look. There's 5 pods, which one")
131 print("do you take?")
132
133 good_pod = randint(1,5)
134 guess = input("[pod #]> ")
135
136 if int(guess) != good_pod:
137 print("You jump into pod %s and hit the eject button." % guess)
138 print("The pod escapes out into the void of space, then")
139 print("implodes as the hull ruptures, crushing your body")
140 print("into jam jelly.")
141 return 'death'
142
143 else:
144 print("You jump into pod %s and hit the eject button." % guess)
145 print("The pod easily slides out into space heading to")
146 print("the planet below. As it flies to the planet, you look")
147 print("back and see your ship implode then explode like a")
148 print("bright star, taking out the Gothon ship at the same")
149 print("time. You won!")
150 exit(0)
151
152
153
154 ROOMS = { 'death': death, 'central_corridor': central_corridor, 'laser_weapon_armory': laser_weapon_armory, 'the_bridge': the_bridge, 'escape_pod': escape_pod }
155
156
157
158 def runner(map, start):
159 next = start
160 while True:
161 room = map[next]
162 print("\n--------")
163 next = room()
164
165 runner(ROOMS, 'central_corridor')
166
#ex41+.py
1 def multiply(a, b):
2 print("MULTIPLYING %d * %d" % (a, b))
3 return a * b
4
5 def subtract(a, b):
6 print("SUBTRACTING %d - %d" % (a, b))
7 c=multiply
8 d=c(a,b)
9 return d
10
11 h=subtract(5, 10)
12 print(h)
笨办法学Python(learn python the hard way)--练习程序41的更多相关文章
- 笨办法学 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 (第三版)(转载)
笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html 摘自https://learn-python ...
- 笨办法学Python - 习题1: A Good First Program
在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...
- 笨办法学python 13题:pycharm 运行
笨办法学python 13题 代码: # -*- coding: utf-8 -*- from sys import argv # argv--argument variable 参数变量 scrip ...
- 笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘
笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘 提取码:xaln 怎样阅读本书 由于本书结构独特,你必须在学习时遵守几条规则 录入所有代码,禁止复制粘贴 一字不差地录入代码 ...
- 笨办法学Python 3|百度网盘免费下载|新手基础入门书籍
点击下方即可百度网盘免费提取 百度网盘免费下载:笨办法学Python 3 提取码:to27 内容简介: 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用. ...
- 《笨办法学 Python(第四版)》高清PDF|百度网盘免费下载|Python编程
<笨办法学 Python(第四版)>高清PDF|百度网盘免费下载|Python编程 提取码:jcl8 笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机 ...
- 笨办法学python 第四版 中文pdf高清版|网盘下载内附提取码
笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机了解不多,没有学过编程,但对编程感兴趣的朋友学习使用.这本书以习题的方式引导读者一步一步学习编 程,从简单的打印一 ...
- 《笨办法学Python 3》python入门书籍推荐|附下载方式
<笨办法学Python 3>python入门书籍免费下载 内容简介 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用.这本书以习题的方式引导读 ...
随机推荐
- 红帽学习笔记[RHCSA] 第七课[网络配置相关]
第七课[网络配置相关] 在Vmware中添加网卡 编辑 -> 编辑虚拟网络 -> 添加网络->随便选择一个如VMnet2-> 选择仅主机模式 -> 勾掉使用本地DHCP服 ...
- disabled_button 按钮按不下去
X老师今天上课讲了前端知识,然后给了大家一个不能按的按钮,小宁惊奇地发现这个按钮按不下去,到底怎么才能按下去 检查元素 删除 按钮就可以摁了 出现答案
- Kinect V2入门之数据获取步骤
在Kinect for windows SDK2.0中,获取并处理数据源接口步骤如下: Sensor -> Source -> Reader -> Frame -> Data ...
- read、readline 和 readlines 的区别?
假设a.txt的内容如下所示: 1 Hello 2 Welcome 3 What is the fuck... read:读取整个文件. read([size])方法从文件当前位置起读取size个字节 ...
- 连连看(简单搜索)bfs
连连看Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- vue中使用better-scroll滚动条插件
应用场景: overflow: hidden会让超出的部分隐藏,并且无法拖拽,所以可使用插件让长列表限定的区域滚动拖拽. 参考:https://zhuanlan.zhihu.com/p/2740702 ...
- vue中获取滚动table的可视页面宽度,调整表头与列对齐(每列宽度不都相同)
mounted() { // 在mounted中监听表格scroll事件 this.$refs.scrollTable.addEventListener( 'scroll',(event) => ...
- c# wpf 加密文本
可以加密人们的内容,文本加密. 界面 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation& ...
- python2和3的一些区别,编码方式
python2与python3的区别: #python2 print() print'abc' #range() xrange()生成器 #raw_input()#python3 #print('ab ...
- 02CSS
1.简介 从事网页制作或者相关工作,就要学习HTML,CSS.其中HTML是网页制作的主要语言网页的基础,CSS层叠样式表,主要用来修饰页面的元素 CSS 是 Cascading Style Shee ...