《笨方法学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 (& ...
随机推荐
- Centos7上安装mariadb
一.查看系统是否安装了mariadb,有的话就删除掉. 1.rpm -qa | grep mariadb 2.rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86 ...
- es6的理解
目录:let——和var的区别const 特性:暂时性死区解构赋值 [] {}属性简洁函数简洁 属性表达式可以作为对象的属性名字符串扩展数组扩展对象扩展 Object.getPrototypeOf(实 ...
- 宝塔面板配置阿里云SSL证书流程
阿里云SSL证书申请过程就不在这里说了 1 先下载阿里云成功申请的SSL证书 解压后 有3个文件 2 找到宝塔面板的 站点设置 找到SSL设置 3 找到其他证书 用文本打开.key文件 复制里面 ...
- Docker 开启 remoter api
debian 环境: vi /lib/systemd/system/dcoker.service 修改: ExecStart=/usr/bin/dockerd -H fd://为 ExecStart= ...
- flask sqlchemy 多对多的自引用关系定义
多对多的定义可以使用关联表,或者重新定义一个模型,通过模型定义多对多的自引用在flask web开发书里有讲到,这里主要演示用关联表定义的方法. from flask_sqlalchemy impor ...
- Vue 自定义指令实现权限控制(按钮级)
在用户登陆后,根据用户id读取用户的所有权限数据,放入本地的sessionStorage进行存储(这里我是拿到权限按钮按钮的标识,英文名称.把他们合成一个字符串存储在 btnPowerString 中 ...
- 记一次easywechat企业付款问题
由easywechat的cli "./vendor/bin/easywechat payment:rsa_public_key" 获取RSA公钥时 生成的.pem文件内的公钥默认是 ...
- vscode垂直选中列选中
VSCode列选择快捷键:Alt+Shift+左键
- Ubuntu搜狗拼音输入法崩溃问题
Ubuntu 14.04.5 LTS 环境下搜狗拼音经常崩溃,似乎也没有什么特别好的解决办法. 以下是重启命令 #!/bin/sh >/dev/>& >/dev/>&a ...
- TCP连接笔记
每个socket套接字都有一个引用计数. 调用close时只是将相应的引用计数减1. 只有当引用计数为0时才会真正的清理套接字资源,也就是发送FIN. 若只是想在某个TCP连接上发送一个FIN可以改用 ...