Learn Python the hard way, ex42 物以类聚
依然少打很多剧情,并修改了很多,还好,能运行
#!urs/bin/python
#coding:utf-8 from sys import exit
from random import randint class Game(object): def __init__(self,start):
self.quips = [
"you died.",
"such a luser.",]
self.start = start def play(self):
next = self.start while True:
print "\n------------"
room = getattr(self,next)
next = room() def death(self):
print self.quips[randint(0,len(self.quips)-1)]
exit(1) def central_corridor(self):
print "in #25 planet"
print "we must find weapon" action = raw_input(">>") if action == "shoot":
print "you died .because shoot"
return 'death'
elif action == 'dodge':
print "you head and eats U"
return 'death'
elif action == "joke":
print "lucky!"
return 'laser'
else:
print "DOES"
return 'central_corridor' def laser(self):
print "you get bomb"
code = "%d" % (randint(1,9))
guess= raw_input("enter key:>>")
guesses = 0 while guess != code and guesses <10:
print "BZZZZZZZZZZZZEDDDDDD"
guesses +=1
guess = raw_input("[enter key:]>>") if guess == code:
print "you guess right"
return 'the_bridge'
else:
print "ship go away and you die"
return 'death' def the_bridge(self):
print "which you choise :" action = raw_input(">>") if action == "throw bomb":
print "it bomb lost"
return 'death' elif action == "get bomb":
print "get it .bomb"
return 'escape_pod'
else:
print "go back"
return 'the_bridge' def escape_pod(self):
print "do U take?" good_pod=randint(1,3)
guess = raw_input('[pod]>>') if int(guess) != good_pod:
print "into jam jelly"
return 'death' else:
print "time ,you won!"
exit(0)
a_game = Game("central_corridor")
a_game.play()
Output:
------------
in #25 planet
we must find weapon
>>joke
lucky! ------------
you get bomb
enter key:>>3
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>5
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>7
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>9
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>2
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>4
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>6
BZZZZZZZZZZZZEDDDDDD
[enter key:]>>8
you guess right ------------
which you choise :
>>get bomb
get it .bomb ------------
do U take?
[pod]>>2
time ,you won! ***Repl Closed***
Learn Python the hard way, ex42 物以类聚的更多相关文章
- 笨办法学 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)
学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注释和井号 习题 ...
- 《Learn python the hard way》Exercise 48: Advanced User Input
这几天有点时间,想学点Python基础,今天看到了<learn python the hard way>的 Ex48,这篇文章主要记录一些工具的安装,以及scan 函数的实现. 首先与Ex ...
- 快速入门:十分钟学会PythonTutorial - Learn Python in 10 minutes
This tutorial is available as a short ebook. The e-book features extra content from follow-up posts ...
- Python basic (from learn python the hard the way)
1. How to run the python file? python ...py 2. UTF-8 is a character encoding, just like ASCII. 3. ro ...
- 笨办法学Python(learn python the hard way)--练习程序42
下面是练习42,基于python3 #ex42.py 1 class TheThing(object): 2 #__init__为class设置内部变量的方式,正常情况下函数内的变量与外部没有关联,但 ...
- Learn Python the hard way, ex41 来自Percal 25 号星星的哥顿人
我承认,我偷懒了,少打了大量代码(剧情),英文太差,下次可以编个中文的试试 #!/urs/bin/python #coding:utf-8 from sys import exit from rand ...
- 笨办法学Python(learn python the hard way)--练习程序31-35
下面是练习31-练习35,基于python3 #ex31.py 1 print("You enter a dark room witn two doors. Do you go throug ...
随机推荐
- win10常用的dos命令
1.calc:启动计算器 2.appwiz.cpl:程序和功能 3.certmgr.msc:证书管理实用程序 4.charmap:启动字符映射表 5.chkdsk.exe:Chkdsk磁盘检查(管理员 ...
- 自定义UICollectionLayout
#import "AppDelegate.h"#import "CircleLayout.h"#import "CollectionViewDataS ...
- 洛谷 P2866 [USACO06NOV]糟糕的一天Bad Hair Day 牛客假日团队赛5 A (单调栈)
链接:https://ac.nowcoder.com/acm/contest/984/A 来源:牛客网 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,00 ...
- CTF各种资源:题目、工具、资料
目录 题目汇总 Reverse 签到题 Web Web中等难度 Crypto 基础网站 各类工具 综合 Web Payloads 逆向 Pwn 取证 题目汇总 这里收集了我做过的CTF题目 Rever ...
- redis-5.0.5 集群部署
之前写过一套基于redis-4.0.6版本的测试集群部署 https://www.cnblogs.com/mrice/p/10730309.html 最近生产环境需要部署一套redis-5.0.5版本 ...
- 【GDOI2016模拟3.10】习用之语
前言 这道题看上去很水,结果我在比赛上浪费了N多时间在上面,但还是没AC.比赛结束后发现:实际上这道题还是是大水. 题目 分析 设字符串c1c2c3c4,其中c1.c2.c3.c4={'0'~'9', ...
- LTE抛弃了CDMA?
原文链接:https://blog.csdn.net/readhere/article/details/82764919 本文节选自<LTE教程:结构与实施> 大家都听说过这样的说法:LT ...
- iOS---实现在屏幕上实时绘图的简单效果---CAShaperLayer和UIBezierPath的简单运用
首先,声明几个属性 @property(nonatomic,strong)UIBezierPath * beizer; @property(nonatomic,assign)CGPoint start ...
- 百度小程序 配置 app.json 文件
可以通过配置 app.json 文件,设置 SWAN 的界面.路径.多 TAB 等. app.json 配置项列表如下 属性 类型 必填 描述 pages Array.<string> 是 ...
- Bugku 杂项 隐写
隐写 下载后打开压缩包发现是一张图片 用winhex打开 图中红色框内是PNG的PE头 在IHDR后面的八个字节(黄色框部分)为该图片的长度.宽度信息 将黄色框内最后一个字节由A4改为F4后另存为图片 ...