题目:

制作一个游戏

知识点:

函数、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)的更多相关文章

  1. Python3练习题系列(09)——物以类聚,人以群分

    目标: 用类管理同类事物 解析: 用到“class”的编程语言被称作“Object Oriented Programming(面向对象编程)”语言.首先你需要做出“东西”来,然后你“告诉”这些东西去完 ...

  2. Python3练习题系列(10)——项目骨架构建

    目标: 如何创建<项目“骨架”目录> 包含:项目文件布局.自动化测试代码,模组,以及安装脚本. 由于编写一个Python文件可以作为一个模块,一个带__init__.py的目录算一个包. ...

  3. Python3练习题系列(06)——各种符号总结

    Python3中的各种符号总结 1关键字 import keyword print(keyword.kwlist, end='\t') ['False', 'None', 'True', 'and', ...

  4. Python3练习题系列(01)

    2018-06-13 题目: 根据用户回答做出相应的判断,完成一个“回答-判断”的小游戏 Python3知识点: if, else, elif 实例代码: print("You enter ...

  5. Python3练习题系列(07)——列表操作原理

    目标: 理解列表方法的真实含义. 操作: list_1.append(element) ==> append(list_1, element) mystuff.append('hello') 这 ...

  6. Python3练习题系列(08)——代码阅读方法及字典跳转表理解

    问题:分析下面代码 cities['_find'] = find_city city_found = cities['_find'](cities, state) 分析过程: 一个函数也可以作为一个变 ...

  7. Python3练习题系列(05)——设计和调试规则

    If 语句的常见规则 1. 每一个“if 语句”必须包含一个else: 2. 如果这个else 永远都不应该被执行到,因为它本身没有任何意义,那你必须在else 语句后面使用一个叫做die 的函数,让 ...

  8. Python3练习题系列(03)

    题目: 思考While循环,看看它的特点是什么? 知识点: while循环 分析: 特点:while-loop(while 循环).while-loop 会一直执行它下面的代码片段,直到它对应的布尔表 ...

  9. Python3练习题系列(02)

    题目: 思考循环结构,看看它是怎样运行的,对我们认识程序有何益处. 知识点: list, for-loop, range 练习代码: 练习1 the_count = [1, 2, 3, 4, 5] # ...

随机推荐

  1. caffe-win10-cifar10另

    上一篇主要以bat形式实现了leveldb形式的cifar10,因为对于shell脚本不甚熟悉,所以这次专门利用.sh调用来实现lmdb形式的cifar10. 1.下载数据 同上一篇. 2.数据转换和 ...

  2. 简述JavaScript作用域与作用域链

    关于变量作用域的知识,相信学习JavaScript的朋友们一定早已经接触过,这里简单列举: JavaScript中变量是以对象属性的形式存在的:全局变量是全局对象的属性:局部变量是声明上下文对象的属性 ...

  3. Salt Document学习笔记2

    配置文件需修改的内容及注意点: Edit the master config file: 1. Uncomment and change the user: root value to your ow ...

  4. Linux无权限上传文件解决办法

    无权限上传文件解决办法 1.当前登录的普通用户:user1/password1 2.切换到管理员(user2)用户: sudo su - user2 输入user2用户的密码:password2 或者 ...

  5. vue系列之过渡效果

    参考地址:http://cn.vuejs.org/v2/guide/transitions.html vue2.0,要想实现过渡效果,要用transition组件 代码: <div id=&qu ...

  6. CGAffineTransform 缩放 / 旋转 / 平移

    CGAffineTransform此类是一个3*3矩阵的变换. - (void)transformImageView { CGAffineTransform t = CGAffineTransform ...

  7. 《剑指offer》-整数中1出现的次数

    题目描述 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了. ...

  8. 【C++ Primer 第11章】4. 无序容器

    一.介绍 1. Hashtable和bucket 由于unordered_map内部采用的hashtable的数据结构存储,所以,每个特定的key会通过一些特定的哈希运算映射到一个特定的位置,我们知道 ...

  9. 关于Spring MVC 中地址栏访问 /WEB-INF下的.jsp

    WEB-INF是对资源的保护,直接在地址栏访问WEB-INF目录下的页面,会显示404,关于为什么要把页面放在WEB-INF下,可以自行百度 在这里我是用SpringMVC 对WEB-INF目录下的页 ...

  10. 【BZOJ5110】[CodePlus2017]Yazid 的新生舞会

    题解: 没笔的时候我想了一下 发现如果不是出现一半次数而是k次,并不太会做 然后我用前缀和写了一下发现就是维护一个不等式: 于是就可以随便维护了