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 ...
随机推荐
- 用eclipse怎么打war包?
用eclipse怎么打war包? 在服务器上部署很多都是用war包进行部署的,eclipse是很友好的支持把java项目打成war包的,下面就把打war的经验写出来,供大家参考 百度经验:jingya ...
- Vim 系列笔记一
Vim 系列笔记一 Vim 简介 什么是VIM ? Vim 是从 Vi 发展出来的一个编辑器,是 Vi 的升级版.而 vi 则是 Unix .类Unix(Linux)系统中自带的编辑器. Vim/Vi ...
- nginx_mirror_module流量复制在项目中的应用
参考文档:https://my.oschina.net/andChow/blog/2873870 https://blog.csdn.net/lancerh/article/details/88645 ...
- DDD领域驱动设计初探(三):仓储Repository(下)
前言:上篇介绍了下仓储的代码架构示例以及简单分析了仓储了使用优势.本章还是继续来完善下仓储的设计.上章说了,仓储的最主要作用的分离领域层和具体的技术架构,使得领域层更加专注领域逻辑.那么涉及到具体的实 ...
- Vue刷新token,判断token是否过期
1.判断token是否过期,前端请求后,后台会返回一个状态给你.根据状态判断是否过期,刷新token 2.是否每次请求后端都会返回新的token给你.或者后端给你定义了一个刷新token的方法,那此时 ...
- Python---进阶---文件操作---比较文件不同
一.编写一个程序,接受用户输入的内容,并且保存为新的文件 如果用户单独输入:w 表示文件保存退出 --------------------------------------------- file_ ...
- 1. svn 简介
参考文档: http://svndoc.iusesvn.com/ SVN的 相关网站 什么是svn?Subversion是一个“集中式”的信息共享系统.版本库是Subversion的核心部分,是数据的 ...
- Linux内核设计与实现 总结笔记(第十一章)定时器和时间管理
时间管理在内核中占用非常重要的地位,内核中有大量的函数都需要基于时间驱动的,内核对相对时间和绝对时间都非常需要. 一.内核中的时间概念 内核必须在硬件的帮助下才能计算和管理时间,系统定时器以某种频率自 ...
- PHP快速教程
1.本文主要针对有C语言(或其他编程语言)基础的人快速学习PHP的,所以不会对一些基础知识作过多解释,比如“=”是赋值不是等于. 2.本文适合已学过一门编程语言,想要快速入门PHP的人. 3.基本上看 ...
- ORACLE动态监听
动态监听的原理 pmon在数据库启动到mount或open时,动态从参数文件中读取service_names值.service_names可以为多值(可以有64个,其中包括两个系统的). servi ...