下面是练习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的更多相关文章

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

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

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

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

  3. 笨办法学 Python (第三版)(转载)

    笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html   摘自https://learn-python ...

  4. 笨办法学Python - 习题1: A Good First Program

    在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...

  5. 笨办法学python 13题:pycharm 运行

    笨办法学python 13题 代码: # -*- coding: utf-8 -*- from sys import argv # argv--argument variable 参数变量 scrip ...

  6. 笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘

    笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘 提取码:xaln  怎样阅读本书 由于本书结构独特,你必须在学习时遵守几条规则 录入所有代码,禁止复制粘贴 一字不差地录入代码 ...

  7. 笨办法学Python 3|百度网盘免费下载|新手基础入门书籍

    点击下方即可百度网盘免费提取 百度网盘免费下载:笨办法学Python 3 提取码:to27 内容简介: 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用. ...

  8. 《笨办法学 Python(第四版)》高清PDF|百度网盘免费下载|Python编程

    <笨办法学 Python(第四版)>高清PDF|百度网盘免费下载|Python编程 提取码:jcl8 笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机 ...

  9. 笨办法学python 第四版 中文pdf高清版|网盘下载内附提取码

    笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机了解不多,没有学过编程,但对编程感兴趣的朋友学习使用.这本书以习题的方式引导读者一步一步学习编 程,从简单的打印一 ...

  10. 《笨办法学Python 3》python入门书籍推荐|附下载方式

    <笨办法学Python 3>python入门书籍免费下载 内容简介 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用.这本书以习题的方式引导读 ...

随机推荐

  1. Mysql 5.7存储过程的学习

    存储过程:对sql的封装和重用,经编译创建并保存在数据库中,通过指定存储过程的名字并给定参数(需要时)来调用执行. 优缺点: (1) 优点: 执行速度快------存储过程只在创建时进行编译,以后每次 ...

  2. Windows 下安装 ElasticSearch 修改 elasticsearch.yml的坑

    注意:  ElasticSerach 集成 IK分词器 的时候,整个路径不能有空格!!! 1. 文件后加入 严格复制粘贴,否则入坑 http.cors.enabled : true http.cors ...

  3. Nginx 2.安装与部署配置

    转 https://www.cnblogs.com/wcwnina/p/8728430.html > 下载 官方网站:https://nginx.org/en/download.html Win ...

  4. docker环境下分析zookeeper观察者角色

    问题引入 zookeeper新引入的角色observer是不参与投票的,通过增加observer节点,可以在提高zk系统读吞吐量时,不影响写吞吐量. 那么问题来了 Zookeeper系统节点如果超过半 ...

  5. Selenium1.0与2.0介绍

    Selenium的实现原理 首先,你要明确刚才建立的测试用例是基于Selenium 2.0,也就是Selenium + WebDriver的方案.其次,你需要知道,对Selenium而言,V1.0和V ...

  6. Python 入门之Python简介

    Python 入门之Python简介 1.Python简介: (1) Python的出生: ​ python的创始人为吉多·范罗苏姆(Guido van Rossum)(中文名字:龟叔).1989年的 ...

  7. stdcall 函数调用过程(以delphi为例),还有负数的补码

    以delphi下调用stdcall 函数为例,从右往左压栈:procedure TForm1.Button2Click(Sender: TObject);var i:integer;begin i:= ...

  8. P3190 [HNOI2007]神奇游乐园

    传送门 第一道插头 $dp$ 由于讲不清楚所以假装各位早就会插头 $dp$ 了 首先要的是一个闭合回路,所以可以用括号表示法表示状态,然后大力分类讨论 $1.$ 没有右插头和下插头 那么我们可以啥也不 ...

  9. Paper Reading_ML for system

    最近(以及预感接下来的一年)会读很多很多的paper......不如开个帖子记录一下读paper心得 SysML相关的文章很多来源于上学期的8980课.有些和具体field(比如DB/architec ...

  10. Redis中的事务及乐观锁的实现

    介绍 Redis中的事务(transaction)是一组命令的集合.     事务同命令一样都是Redis最小的执行单位,一个事务中的命令要么都执行,要么都不执行.     Redis事务的实现需要用 ...