下面是练习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. Java第二周总结

    一.Java 基础程序设计 第一章: (1)在Java中源文件的扩展名为.java,编译Java源程序文件产生相应的字节码文件扩展名为.class (2)public class定义要求类名称保持一致 ...

  2. oracle_fdw安装及使用(无法访问oracle存储过程等对象)

    通过oracle_fdw可以访问oracle中的一些表和视图,也可以进行修改,尤其是给比较复杂的系统使用非常方便. (但不能使用oracle_fdw来访问oracle的存储过程.包.函数.序列等对象) ...

  3. SCUT - G - 魔法项链 - 树状数组

    https://scut.online/contest/30/G 很久以前做的一个东西,当时是对R排序之后树状数组暴力统计当前区间的前缀和.每有一个元素出现在R的范围内,就解除他的同样元素的影响,在他 ...

  4. 通过编写串口助手工具学习MFC过程--(十一)弹出模态型对话框

    通过编写串口助手工具学习MFC过程 因为以前也做过几次MFC的编程,每次都是项目完成时,MFC基本操作清楚了,但是过好长时间不再接触MFC的项目,再次做MFC的项目时,又要从头开始熟悉.这次通过做一个 ...

  5. go & cron

    https://github.com/robfig/cron - 源码 cron - GoDoc 参考 go---定时任务 cron,gin 静态文件 go语言里比较好用的计划任务调度模块

  6. 如何将一个.NET Core类库发布到NuGet

    包治百病 | 如何将一个.NET Core类库发布到NuGet 写文章 包治百病 | 如何将一个.NET Core类库发布到NuGet Edi Wang发表于汪宇杰博客订阅 77 NuGet是.NET ...

  7. STL之 stack

    栈的常用操作函数:top()push()pop()size()empty() 建栈: stack<int> st; stack<int> st[4]; 四个栈 //可以使用li ...

  8. 出去就餐并且理解Express.js的基本知识

    Going out to eat and understanding the basics of Express.js出去就餐并且理解Express.js的基本知识 原文:Going out to e ...

  9. js中的object类型

    特点: 每个Object类型的实例共有的属性和方法: constructor: 保存着用于创建当前对象的函数. hasOwnProperty:用于检测给定的属性在当前对象的实例中是否存在. isPro ...

  10. MongoDB的使用学习之(五)Spring集成MongoDB以及简单的CRUD

    这篇文章不错:Spring Data - MongoDB 教程 (1.0.0.M1)http://miller-cn.iteye.com/blog/1258859 1.介绍 之前在很多地方一直见到这个 ...