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 ...
随机推荐
- IIC通信协议详解
IIC通信详解 IIC概述 IIC:两线式串行总线,它是由数据线SDA和时钟线SCL构成的串行总线,可发送和接收数据. 在CPU与被控IC之间.IC与IC之间进行双向传送,高速IIC总线一般可达400 ...
- Java 关于SpringbootJPA分页及排序
创建Pageable对象 看了网上很多博客,都是在用 new PageRequest的方法创建Pageable对象.可是估计很多同学写了之后才发现原来这个方法作者已经标记为过时了: 替代的方法是不要n ...
- CentOS7 编译安装python3.6.8(升级python)
1.安装依赖包和需要用到的工具 yum -y install wget openssl openssl-devel 这里如果不升级openssl,安装后pip安装模块可能会出错.点我查看pip安装模块 ...
- 矩阵快速幂 求斐波那契第N项
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> us ...
- ocvate常用函数
1.生成矩阵相关 https://www.coursera.org/learn/machine-learning/lecture/9fHfl/basic-operations 1. 初始化矩阵 a = ...
- Linux加载一个可执行程序并启动的过程
原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 作者:严哲璟 以shell下 ...
- Python---进阶---常用模块os、jso
一.写一个6位随机验证码程序(使用 random模块),要求验证码中至少包含一个数字.一个小写字母.一个大写字母 import randomimport string #help(string) co ...
- Eclipse设置类和方法的注释模板
一.打开设置模板的窗口:Window->Preference->Java->Code Style->Code Template展开Comments,最常用的就是类和方法的注释, ...
- 面向对象this关键字和概述和应用
面向对象this关键字和概述和应用 package thisdemo; /** * 面向对象this关键字和概述和应用 * */ //定义老师类 class Teacher { private Str ...
- 【转】Django框架请求生命周期
https://www.cnblogs.com/gaoya666/p/9100626.html 先看一张图吧! 1.请求生命周期 - wsgi, 他就是socket服务端,用于接收用户请求并将请求进行 ...