题目:

制作一个游戏

知识点:

函数、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. ftpdata目录下日期目录权限问题

    由于APP Server由root用户启动,创建目录默认为root:root用户:用户组权限 需chown -R wingupload ftpdata执行后,WING才能上传成功 或者写成脚本,每天凌 ...

  2. python将图片转换为Framebuffer裸数据格式(终端显示图片)【转】

    转自:https://www.cnblogs.com/zqb-all/p/6107905.html 要在ubuntu终端显示图片或者在板子的LCD显示图片,Framebuffer是一个简单易用的接口, ...

  3. hostapd 和 wap_supplicant

    hostapd : user space daemon for access points, including, e.g., IEEE 802.1X/WPA/EAP Authenticator fo ...

  4. 创建物理卷报错Can't open /dev/sdb5 exclusively. Mounted filesystem的问题解决过程记录

    yum服务器lvm扩容,data目录是yum存放rpm包的目录,只有20G,需要添加磁盘扩容到80G # df -lh Filesystem                 Size  Used Av ...

  5. Vue+ajax的使用小结

    js var vue = new Vue({ el:"#vueid", data:{ selectById : "", }, methods:{ yourMet ...

  6. SPI、IIC、IIS、UART、CAN、SDIO、GPIO、USB总线协议

    SPI.IIC.IIS.UART.CAN.SDIO.GPIO总线协议 SPI(Serial Peripheral Interface:串行外设接口)SPI总线由三条信号线组成:串行时钟(SCLK).串 ...

  7. PYTHON-有参装饰器,无参装饰器,语法糖

    装饰器 装饰器就是闭包函数的一种应用场景 一 为何要用装饰器 #开放封闭原则:对修改封闭,对扩展开放 二 什么是装饰器 装饰器他人的器具,本身可以是任意可调用对象,被装饰者也可以是任意可调用对象. 强 ...

  8. PHP获取文件大小的方法详解

    对于初入门的PHP新手来说,PHP获取文件大小这个功能实现,或许有一定的难度.但是相信新手小白们在看过本篇文章介绍后,一定能轻松掌握PHP获取文件大小的重要知识! 下面我们通过具体的代码示例,为大家详 ...

  9. web----Twisted

    Twisted模块: Twisted是一个事件驱动的网络框架,其中包含了诸多功能,例如:网络协议.线程.数据库管理.网络操作.电子邮件等.

  10. poj2739 poj2100 尺取法基础(二)

    都是很简单的题目 poj2739素数打表+单点推移 #include<iostream> #include<cstring> #include<cstdio> us ...