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的更多相关文章

  1. "笨方法学python"

    <笨方法学python>.感觉里面的方法还可以.新手可以看看... 本书可以:教会你编程新手三种最重要的技能:读和写.注重细节.发现不同.

  2. 笨方法学python 22,前期知识点总结

    对笨方法学python,前22讲自己的模糊的单词.函数进行梳理总结如下: 单词.函数 含义 print() 打印内容到屏幕 IDLE 是一个纯Python下自带的简洁的集成开发环境 variable ...

  3. 笨办法学python 13题:pycharm 运行

    笨办法学python 13题 代码: # -*- coding: utf-8 -*- from sys import argv # argv--argument variable 参数变量 scrip ...

  4. 《笨方法学Python》加分题20

    加分练习通读脚本,在每一行之前加注解,以理解脚本里发生的事情.每次 print_a_line 运行时,你都传递了一个叫 current_line 的变量,在每次调用时,打印出 current_line ...

  5. 《笨方法学Python》加分题17

    题目通过前学习的文件操作把一个文件中的内容拷贝到另一个文件中,并使用 os.path.exists 在拷贝前判断被拷贝的文件是否已经存在,之后由用户判断是否继续完成拷贝. 新知识os.path.exi ...

  6. 《笨方法学Python》加分题15

    本题本题开始涉及文件的操作,文件操作是一件危险的事情,需要仔细细心否则可能导致重要的文件损坏. 本题除了 ex15.py 这个脚本以外,还需要一个用来读取的文件 ex15_sample.txt 其内容 ...

  7. 《笨方法学Python》加分题33

    while-leep 和我们接触过的 for-loop 类似,它们都会判断一个布尔表达式的真伪.也和 for 循环一样我们需要注意缩进,后续的练习会偏重这方面的练习.不同点在于 while 循环在执行 ...

  8. 《笨方法学Python》加分题29

    加分练习猜一猜 “if 语句” 是什么,他有什么作用.在做下一道题之前,试着用自己的话回答下面的问题: 你认为 if 对他下一行代码做了什么?为什么 if 语句的下一行需要 4 个空格缩进?如果不缩进 ...

  9. 《笨方法学Python》加分题28

    #!usr/bin/python # -*-coding:utf-8-*- True and True print ("True") False and True print (& ...

随机推荐

  1. C#创建windows服务并发布

    创建window 服务 新建一个window 服务项目MyService,如下图 切换到代码视图修改. using System; using System.Collections.Generic; ...

  2. .NET Core 中的通用主机和后台服务

    简介 我们在做项目的时候, 往往要处理一些后台的任务. 一般是两种, 一种是不停的运行,比如消息队列的消费者.另一种是定时任务. 在.NET Framework + Windows环境里, 我们一般会 ...

  3. eclipse安装中文语言包

    打开eclipse官网 https://www.eclipse.org/ 选择Projects 搜索框输入:Babel 点击搜索 选择Downloads 根据eclipse启动图画里的版本选择要下载的 ...

  4. abc

    无类型: 汇编弱类型.静态类型 : C/C++弱类型.动态类型检查: Perl/PHP强类型.静态类型检查 :Java/C#强类型.动态类型检查 :Python, Scheme静态显式类型 :Java ...

  5. python 反射 hasattr getattr

    class BlackMedium:     feature='Ugly'     def __init__(self,name,addr):         self.name=name       ...

  6. python学习笔记----正则表达式

    正则: regular expression 常用的场景: #正则的包 >>> import re #match:开头匹配,匹配到,返回一个匹配对象,否则返回None >> ...

  7. 整合MVC实现文件上传

    1.整合MVC实现文件上传整合MVC实现文件上传在实际的开发中在实现文件上传的同时肯定还有其他信息需要保存到数据库,文件上传完毕之后需要将提交的基本信息插入数据库,那么我们来实现这个操作.整个MVC实 ...

  8. Android转换集合数据(ArrayList)为Json格式并上传服务器

    使用Gson上传集合数据到服务器,1.最外层用 ArrayMap<String, Object> 封装:2.通过  mRequestParam.put("cmdLineIds&q ...

  9. 关于SQL 导出脚本失败 及SQL 的重装

    说点题外话 最近跳到一家新公司 薪资比较客观 但是技术可能不太尽如人意 而且对.Net方向的开发好像不是很友好  自己也不知道该怎么办 一个人大老远跑这边来 附近也没有什么.net的公司和职位 房子租 ...

  10. 使用电脑ODBC测试数据库连接方法

    使用电脑ODBC测试数据库连接方法 一.打开电脑的控制面板——管理工具——数据源(ODBC),在用户dsn页面中点击添加按钮,选择IBM DB2 ODBC DRIVER,点击完成. 二.在弹出的配置页 ...