《笨方法学Python》加分题35
sys.exit 用于结束程序
from sys import exit # 进入黄金房间后的逻辑
def gold_room():
print("This room is full of gold. How much do you take?") choice = input("> ")
# 如果输入不包含 0 或 1 则死
if "" in choice or "" in choice:
how_much = int(choice)
else:
dead("Man, learn to type a number.") # 如果输入的数字大于等于 50 则死
if how_much < 50:
print("Nice, you're not greedy, you win!")
exit(0)
else:
dead("You greedy basterd!") # 实现熊房间的逻辑
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 循环了.
while True:
# print(">>> bear_moved1 = ", bear_moved)
choice = input("> ") if choice == "take honey":
# print(">>> bear_moved2 = ", bear_moved)
dead("The bear looks at you then slaps your face off.")
elif choice == "taunt bear" and not bear_moved:
# print(">>> bear_moved3 = ", bear_moved)
print("The bear has moved from the door.")
print("You can go through it now.")
bear_moved = True
elif choice == "taunt bear" and bear_moved:
# print(">>> bear_moved4 = ", bear_moved)
dead("The bear gets pissed off and chews your legs off.")
elif choice == "open door" and bear_moved:
# print(">>> bear_moved5 = ", bear_moved)
gold_room()
else:
print("I go no idea what that means.") # 恶魔房逻辑
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 for your life or eat your head?") choice = input("> ") # 二选一,否则恶魔放循环
if "flee" in choice:
start()
elif "head" in choice:
dead("Well that was tasty!")
else:
cthulhu_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 right and left.")
print("Which one do you take?") choice = input("> ") if choice == "left":
bear_room()
elif choice == "right":
cthulhu_room()
else:
dead("You stumble around the room until you starve.") # 开始游戏
start()
运行结果

《笨方法学Python》加分题35的更多相关文章
- "笨方法学python"
<笨方法学python>.感觉里面的方法还可以.新手可以看看... 本书可以:教会你编程新手三种最重要的技能:读和写.注重细节.发现不同.
- 笨方法学python 22,前期知识点总结
对笨方法学python,前22讲自己的模糊的单词.函数进行梳理总结如下: 单词.函数 含义 print() 打印内容到屏幕 IDLE 是一个纯Python下自带的简洁的集成开发环境 variable ...
- 笨办法学python 13题:pycharm 运行
笨办法学python 13题 代码: # -*- coding: utf-8 -*- from sys import argv # argv--argument variable 参数变量 scrip ...
- 《笨方法学Python》加分题20
加分练习通读脚本,在每一行之前加注解,以理解脚本里发生的事情.每次 print_a_line 运行时,你都传递了一个叫 current_line 的变量,在每次调用时,打印出 current_line ...
- 《笨方法学Python》加分题17
题目通过前学习的文件操作把一个文件中的内容拷贝到另一个文件中,并使用 os.path.exists 在拷贝前判断被拷贝的文件是否已经存在,之后由用户判断是否继续完成拷贝. 新知识os.path.exi ...
- 《笨方法学Python》加分题15
本题本题开始涉及文件的操作,文件操作是一件危险的事情,需要仔细细心否则可能导致重要的文件损坏. 本题除了 ex15.py 这个脚本以外,还需要一个用来读取的文件 ex15_sample.txt 其内容 ...
- 《笨方法学Python》加分题33
while-leep 和我们接触过的 for-loop 类似,它们都会判断一个布尔表达式的真伪.也和 for 循环一样我们需要注意缩进,后续的练习会偏重这方面的练习.不同点在于 while 循环在执行 ...
- 《笨方法学Python》加分题29
加分练习猜一猜 “if 语句” 是什么,他有什么作用.在做下一道题之前,试着用自己的话回答下面的问题: 你认为 if 对他下一行代码做了什么?为什么 if 语句的下一行需要 4 个空格缩进?如果不缩进 ...
- 《笨方法学Python》加分题28
#!usr/bin/python # -*-coding:utf-8-*- True and True print ("True") False and True print (& ...
随机推荐
- C# Global定时执行Global文件aTimer处理
public class Global : System.Web.HttpApplication { private static event Action eventActions; /// < ...
- MySQL(进阶部分)
视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用. SELECT * FROM ( SEL ...
- sql day2
-- 数据的准备 -- 创建一个数据库 create database python_test charset=utf8; -- 使用一个数据库 use python_test; -- 显示使用的当前 ...
- mybatis映射文件#与$的使用,及参数传入规则
mybaits映射文件中使用#与$场景: <select id="getProviders" resultType="com.lazy.bill.pojo.Prov ...
- TCPlayer web切换播放问题
遇到播放的视频无法切换的问题,,即便是清除标签重新生成也不行~~ 需要使用自带的API ~别无他法 demo: http://imgcache.qq.com/open/qcloud/video/tcp ...
- python之路:变量与变量基本操作(老王版)
python开发之路:变量与变量基本操作 你是一个师范大学的优秀毕业生,现在在某某小学工作. 你想:判作业真的很累,隔壁老王现在天天玩<蓝月传奇>,银行里存满了钱.唉,每节课1个小时,每个 ...
- Dnsmasq 配置PXE批量安装系统
以下测试都是基于centos 7下的环境 需要安装的软件为 nginx 用来下载ks.cfg和系统镜像文件用的,也可以用ftp服务器来代替 dnsmasq 提供dhcp服务和tftp服务,也可以单独去 ...
- nginx stream module on mt7621(newifi3 d2) with openwrt 18.06.2
因为需要使用nginx的stream模块,专门编译了一个nginx安装包,适用于openwrt 18.06.2版本,mt7621平台 顺便记录一下编译的笔记: 1.修改feeds/packages/n ...
- 将ipad作为电脑拓展屏或分屏的简单方法
用Ipad实现电脑分屏的方法是挺简单的,但鉴于部分小白找不到合适的门路,在此重新分享一下. 需要的装备: ipad 电脑 数据连接线 方法:某宝上搜索 duet display ,只需1元左 ...
- errors collectiions
c/c++中出现“undefined reference to”的解决 如果提示未定义的函数是某个库的函数.检查库时候已经安装,并在编译命令中采用-l和-L参数导入库. 如果提示未定义的函数是程序中的 ...