Python3练习题系列(04)
题目:
制作一个游戏
知识点:
函数、if_elif_else, while, exit
游戏图谱:

游戏代码:
from sys import exit def gold_room():
print('This room is full of gold. How much do you take?') next = input("> ") if "" in next or "" in next:
how_much = int(next)
else:
dead("Man, you're not greedy, you win!") if how_much < 50:
print("Nice, you're not greedy, you win!")
exit(0)
else:
dead("You greedy bastard!") # bastard 英 ['bɑːstəd; 'bæst-] 美 ['bæstɚd] adj. 私生的 n. 私生子 # greedy 英 ['griːdɪ] 美 ['gridi] adj. 贪婪的;贪吃的;渴望的 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 = 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 leg off.")
elif next == 'open door' and bear_moved:
gold_room()
else:
print("I got no idea what that means.") '''
taunt 英 [tɔːnt] 美 [tɔnt] n. 嘲弄;讥讽 adj. 很高的 vt. 奚落;逗弄 ''' def cthulhu_room():
print("Here you see the great evil Cthulhu.")
print("He, it, whatever stares at you and you go insane.")
print("Do you flee your life or eat your head?") next = input("> ")
if 'flee' in next:
start()
elif 'head' in next:
dead("Well that was tasty!")
else:
cthulhu_room() # insane 英 [ɪn'seɪn] 美 [ɪn'sen] adj. 疯狂的;精神病的;极愚蠢的 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 right and left.")
print("Which one do you take?") next = input("> ")
if next == 'left':
bear_room()
elif next == 'right':
cthulhu_room()
else:
dead("You stumble around the room until you starve.") start() # stumble 英 ['stʌmb(ə)l] 美 ['stʌmbl] n. 绊倒;蹒跚而行 vi. 踌躇,蹒跚;失足;犯错 vt. 使…困惑;使…绊倒
玩游戏过程:
You are in a dark room.
There is a door to your right and left.
Which one do you take?
> left
There is a bear here.
The bear has a bunch of honey.
The fat bear is in front of another door.
How are you going to move the bear?
> taunt bear
The bear has moved from the door. You can go through it now.
> open door
This room is full of gold. How much do you take?
> 60
You greedy bastard! Good job!
SystemExit: 0 来自《笨办法学Python》
Python3练习题系列(04)的更多相关文章
- Python3练习题系列(09)——物以类聚,人以群分
目标: 用类管理同类事物 解析: 用到“class”的编程语言被称作“Object Oriented Programming(面向对象编程)”语言.首先你需要做出“东西”来,然后你“告诉”这些东西去完 ...
- Python3练习题系列(10)——项目骨架构建
目标: 如何创建<项目“骨架”目录> 包含:项目文件布局.自动化测试代码,模组,以及安装脚本. 由于编写一个Python文件可以作为一个模块,一个带__init__.py的目录算一个包. ...
- Python3练习题系列(06)——各种符号总结
Python3中的各种符号总结 1关键字 import keyword print(keyword.kwlist, end='\t') ['False', 'None', 'True', 'and', ...
- Python3练习题系列(01)
2018-06-13 题目: 根据用户回答做出相应的判断,完成一个“回答-判断”的小游戏 Python3知识点: if, else, elif 实例代码: print("You enter ...
- Python3练习题系列(07)——列表操作原理
目标: 理解列表方法的真实含义. 操作: list_1.append(element) ==> append(list_1, element) mystuff.append('hello') 这 ...
- Python3练习题系列(08)——代码阅读方法及字典跳转表理解
问题:分析下面代码 cities['_find'] = find_city city_found = cities['_find'](cities, state) 分析过程: 一个函数也可以作为一个变 ...
- Python3练习题系列(05)——设计和调试规则
If 语句的常见规则 1. 每一个“if 语句”必须包含一个else: 2. 如果这个else 永远都不应该被执行到,因为它本身没有任何意义,那你必须在else 语句后面使用一个叫做die 的函数,让 ...
- Python3练习题系列(03)
题目: 思考While循环,看看它的特点是什么? 知识点: while循环 分析: 特点:while-loop(while 循环).while-loop 会一直执行它下面的代码片段,直到它对应的布尔表 ...
- Python3练习题系列(02)
题目: 思考循环结构,看看它是怎样运行的,对我们认识程序有何益处. 知识点: list, for-loop, range 练习代码: 练习1 the_count = [1, 2, 3, 4, 5] # ...
随机推荐
- RNN(2) ------ “《A Critical Review of Recurrent Neural Networks for Sequence Learning》RNN综述性论文讲解”(转载)
原文链接:http://blog.csdn.net/xizero00/article/details/51225065 一.论文所解决的问题 现有的关于RNN这一类网络的综述太少了,并且论文之间的符号 ...
- pytorch官网上两个例程
caffe用起来太笨重了,最近转到pytorch,用起来实在不要太方便,上手也非常快,这里贴一下pytorch官网上的两个小例程,掌握一下它的用法: 例程一:利用nn 这个module构建网络,实现 ...
- Vue项目启动后首页URL带的#该怎么去掉?
修改router的mode为history就可以 const router = new VueRouter({mode: 'history', routes: [...]}) 实际修改后需要注意修改a ...
- 如何理解深度学习中的Transposed Convolution?
知乎上的讨论:https://www.zhihu.com/question/43609045?sort=created 不过看的云里雾里,越看越糊涂. 直到看到了这个:http://deeplearn ...
- 【docker】资料
https://yeasy.gitbooks.io/docker_practice/content/network/linking.html
- pyhon----模块
sys模块: sys.argv 命令行参数List,第一个元素是程序本身路径 sys.exit(n) 退出程序,正常退出时exit(0) sys.version 获取Python解释程序的版本信息 s ...
- cf1061D 贪心+multiset 好题!
cf上的思维题真好! 本题是在模拟的基础上贪心即可:将n段时间按照左端点(右端点为第二关键字)从小到大排序,然后遍历每一个时间段. 对于每一个时间段[li,ri],先找到multiset中最靠近li但 ...
- poj3237树链剖分边权+区间取负
树链剖分+线段树lazy-tag在树链上操作时千万不要写错.. /* 树链剖分+线段树区间变负 */ #include<iostream> #include<cstring> ...
- 性能测试十二:jmeter进阶之java请求参数化
如项目中的ip.端口号之类的,都可以在此代码中定义 public Arguments getDefaultParameters() { // TODO Auto-generated method st ...
- 内连接,外链接(左连接、右连接、全连接),交叉连接大总结+附SQL JOINS图解[转]
1.什么是连接查询呢? 概念:根据两个表或多个表的列之间的关系,从这些表中查询数据. 目的:实现多个表查询操作. 2.分类: 首先划分一下,连接分为三种:内连接.外连接.交叉连接 内连接(INNER ...