Learn Python the hard way, ex35 分支和函数
#!/usr/bin/python
#coding:utf-8
from sys import exit def gold_room():
print "this room is full of gold. how much do you take?" next = raw_input(">>")
if "" in next or "" in next:
how_much = int(next)
else:
dead("man, learn to type a number") if how_much < 50:
print "nice,you're not greedy,you win"
exit(0)
else:
dead("you greedy bastard") def bear_room():
print "there is a bear here"
print "the bear has a bunch of honey"
print "the fat bear is in front of another door."
print "how are you going to move the bear?"
bear_moved = False while True:
next = raw_input(">>") if next == "take honey":
dead("the bear looks at you then slaps your face off")
elif next == "taunt bear" and not bear_moved:
print "the bear has moved from the door.you can go through it now"
bear_moved = True
elif next == "taunt bear" and bear_moved:
dead("the bear gets pissed off and chews your legs off")
elif next == "open door" and bear_moved:
gold_room()
else:
print "I got no idea what that means" def cloth_room():
print "here you see the great evil cthulhu"
print "he , it,whatever stares at you and you go insane"
print "do you flee for your life or eat your head?" next = raw_input(">>") if "flee" in next:
start()
elif "head" in next:
dead("well that was tasty")
else:
cloth_room() def dead(why):
print why,"good job"
exit(0) def start():
print "you are in a dark room"
print "there is a door to your left and right"
print "which one do you take?" next = raw_input(">>") if next == "left":
bear_room()
elif next == "right":
cloth_room()
else:
dead("you stumble around the room until you starve") start()
相关函数:
Learn Python the hard way, ex35 分支和函数的更多相关文章
- [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: 注 ...
- 学 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 ...
- python中列表和字典常用方法和函数
Python列表函数&方法 Python包含以下函数: 序号 函数 1 cmp(list1, list2)比较两个列表的元素 2 len(list)列表元素个数 3 max(list)返回列表 ...
- Python 几个重要的内置函数
所谓内置函数,就是在Python中被自动加载的函数,任何时候都可以用.内置函数,这意味着我们不必为了使用该函数而导入模块.不必做任何操作,Python 就可识别内置函数.在学习Python的过程中,有 ...
- 【python】dir(__builtins__)查看python中所用BIF(内置函数)
dir(__builtins__)查看python中所用BIF(内置函数)
- Python核心编程读笔 10:函数和函数式编程
第11章 函数和函数式编程 一 调用函数 1 关键字参数 def foo(x): foo_suite # presumably does some processing with 'x' 标准调用 ...
- 初学 Python(十二)——高阶函数
初学 Python(十二)--高阶函数 初学 Python,主要整理一些学习到的知识点,这次是高阶函数. #-*- coding:utf-8 -*- ''''' 话说高阶函数: 能用函数作为参数的函数 ...
随机推荐
- spring data solr 搜索关键字高亮显示
spring data solr 搜索关键字高亮显示 public Map<String, Object> highSearch(Map searchMap) { Map map = ne ...
- 《剑指offer》面试题13 在O(1)时间删除链表节点 Java版
这道题的关键是知道找到尾节点的前一个节点必须遍历,而且这样做了之后总的时间复杂度还是O(1),以及如何不破坏链表删除一个已知节点 public ListNode delete(ListNode hea ...
- [BZOJ 2199] [USACO11JAN] 大陆议会The Continental Cowngress(2-SAT)
[BZOJ 2199] [USACO11JAN] 大陆议会The Continental Cowngress(2-SAT) 题面 题面较长,略 分析 考虑把问题转化成一个依赖性问题 我们把每只奶牛投出 ...
- 你所遵循的PEP8代码规范是什么?请举例说明其要求?
1. 变量常量:大写加下划线 USER_CONSTANT.私有变量 : 小写和一个前导下划线 _private_value.Python 中不存在私有变量一说,若是遇到需要保护的变量,使用小写和一个前 ...
- 搜索(DFS)---好友关系的连通分量数目
好友关系的连通分量数目 547. Friend Circles (Medium) Input: [[1,1,0], [1,1,0], [0,0,1]] Output: 2 Explanation:Th ...
- 多个nginx之间如何实现反向代理和负责均衡
1)nginx反向代理: http { upstream routeadmin { ip_hash; server 127.0.0.1:9201 weight= ...
- swift实现线程安全的栈和队列
实现一个线程安全的栈 这里使用数组来存储栈的数据.不足之处在于本例中的Stack可以无限扩容,更好的是初始化时候指定一个最大容量,防止不断扩容申请内存导致内存不够的问题.这里的线程安全使用一个串行队列 ...
- RSA加密原理与秘钥、公钥生成
RSA加密(非对称加密) RSA公开密钥密码体制.所谓的公开密钥密码体制就是使用不同的加密密钥与解密密钥,是一种“由已知加密密钥推导出解密密钥在计算上是不可行的”密码体制.(不可逆向运算的加密方法) ...
- Python基础入门一文通 | Python2 与Python3及VSCode下载和安装、PyCharm激活与安装、Python在线IDE、Python视频教程
目录 1. 关键词 2. 推荐阅读 2.1. 视频教程 3. 本文按 4. 安装 4.1. 视频教程 4.2. 资源下载 4.3. 安装教程 1. 关键词 Python2 与Python3及VSCod ...
- unittest单元测试框架总结(转)
unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果.今天笔者 ...