依然少打很多剧情,并修改了很多,还好,能运行

 #!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 物以类聚的更多相关文章

  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 (Learn Python The Hard Way)

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

  4. 《Learn python the hard way》Exercise 48: Advanced User Input

    这几天有点时间,想学点Python基础,今天看到了<learn python the hard way>的 Ex48,这篇文章主要记录一些工具的安装,以及scan 函数的实现. 首先与Ex ...

  5. 快速入门:十分钟学会PythonTutorial - Learn Python in 10 minutes

    This tutorial is available as a short ebook. The e-book features extra content from follow-up posts ...

  6. 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 ...

  7. 笨办法学Python(learn python the hard way)--练习程序42

    下面是练习42,基于python3 #ex42.py 1 class TheThing(object): 2 #__init__为class设置内部变量的方式,正常情况下函数内的变量与外部没有关联,但 ...

  8. Learn Python the hard way, ex41 来自Percal 25 号星星的哥顿人

    我承认,我偷懒了,少打了大量代码(剧情),英文太差,下次可以编个中文的试试 #!/urs/bin/python #coding:utf-8 from sys import exit from rand ...

  9. 笨办法学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 ...

随机推荐

  1. Python 余弦相似度与皮尔逊相关系数 计算

    夹角余弦(Cosine) 也可以叫余弦相似度. 几何中夹角余弦可用来衡量两个向量方向的差异,机器学习中借用这一概念来衡量样本向量之间的差异. (1)在二维空间中向量A(x1,y1)与向量B(x2,y2 ...

  2. c++ Socket客户端和服务端示例版本三(多线程版本)

    客户端 #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/soc ...

  3. SPSS25 下载安装和激活

    目录 1. 其他版本 2. 安装步骤 3. 下载地址 1. 其他版本 参考:https://www.cnblogs.com/coco56/p/11648399.html 2. 安装步骤 打开安装包 下 ...

  4. PAT Advanced 1058 A+B in Hogwarts (20 分)

    If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- a ...

  5. linux extglob模式 和rm反选,除了某个文件外的其他文件全部删除的命令

    1.extglob模式开启之后Shell可以另外识别出5个模式匹配操作符,能使文件匹配更加方便. 不然不识别 #开启命令: shopt -s extglob #关闭命令: shopt -u extgl ...

  6. 【串线篇】spring boot整合SpringData JPA

    一.SpringData简介 其中SpringData JPA底层基于hibernate 二.整合SpringData JPA JPA: Java Persistence API的简称,中文名Java ...

  7. 【SaltStack官方版】—— states教程, part 3 - 定义,包括,延伸

    STATES TUTORIAL, PART 3 - TEMPLATING, INCLUDES, EXTENDS 本教程建立在第1部分和第2部分涵盖的主题上.建议您从此开始.这章教程我们将讨论更多  s ...

  8. 【NOIP2013模拟】DY引擎

    题目 BOSS送给小唐一辆车.小唐开着这辆车从PKU出发去ZJU上课了. 众所周知,天朝公路的收费站超多的.经过观察地图,小唐发现从PKU出发到ZJU的所有路径只会有N(2<=N<=300 ...

  9. Node.js 版本管理工具——nvm

    日常项目开发中,有些项目可能基于node  V10 或者 V8 不同的版本: 如果我们手动安装卸载node,这样是不友好. 先放上作者的博客地址 : https://www.cnblogs.com/g ...

  10. 【转】解决ajax跨域问题的5种解决方案

    转自: https://blog.csdn.net/itcats_cn/article/details/82318092   什么是跨域问题?跨域问题来源于JavaScript的"同源策略& ...