笨办法学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] 第一课[Shell、基础知识]
关于Shell Shell是什么 Shell是系统的用户界面,提供了用户与内核进行交互操作的一种接口.它接收用户输入的命令并把它送入内核中执行. bash shell是大多数Linux的缺省shell ...
- 2019第二周总结.Java
本学期开始学习Java课程了,首先我先说说学习Java的感觉吧,它不像C语言程序设计,但是又有语言开发的共同点.学Java语言重点是面向对象的程序设计,更加的适应生活需要和计算机开发的需要. 总的来讲 ...
- 2019CSP-S游记(?)
认识我的人都知道,我懒得写算法和模拟赛的博客,但是游记就不一样了,它比较好玩. Day0 中午随便收拾了下就坐高铁出发了,一个小时左右就到南昌了,随后坐公交,再步行到宾馆安置(也没多远). 宾馆离学校 ...
- vue使用笔记二
es6\es2015特性http://lib.csdn.net/article/reactnative/58021?knId=1405 使用express-generator初始化你的项目目录http ...
- docker配置文件不生效
1.查看docker配置文件位置 systemctl status docker.service 2.修改docker配置文件 vim /lib/systemd/system/docker.servi ...
- [BZOJ 3123] [SDOI 2013]森林(可持久化线段树+并查集+启发式合并)
[BZOJ 3123] [SDOI 2013]森林(可持久化线段树+启发式合并) 题面 给出一个n个节点m条边的森林,每个节点都有一个权值.有两种操作: Q x y k查询点x到点y路径上所有的权值中 ...
- Burp Suite详细使用教程-Intruder模块详3
Burp Suite使用详细教程连载的第三章.0×02 Intruder—内置有效负荷测试使用技巧内置有效负荷测试选择项如下图: 今天的小技巧使用的是 numbers,给大伙科普下:Numbers 数 ...
- 剑指offer 删除链表的节点
给定单向链表的头指针和一个节点指针,定义一个函数在O(1)时间内删除该节点. struct ListNode { int val; ListNode *next; }; void DeleteNode ...
- django基础篇05-Form验证组件
Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 基本简单的操作: from django im ...
- Ubuntu16.04 php7.1安装redis扩展
sudo apt install php7.1-redis //修改php配置 vi /etc/php.ini 添加extension=redis.so