《笨方法学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 (& ...
随机推荐
- Hexo+Github博客最简教程-Dockerfile自动搭建
闲谈 拿出你的气质,打开你的电脑,借你半小时搭建好属于你的hexo博客,小生用dockerfile自动帮你搭建好:你只需要在你的mac或linux或windows上提前把docker安装好,如何安装不 ...
- iOS字符串自动计算文本的宽和高
根据字符串如何自动计算出这些字符所占的宽和高: 首先,需要知道要显示的字体的样式,因为不同大小的字体所占据的空间大小不一样. 其次,要设置限制范围,例如一串字符可以显示成一行(较宽),也可以显示成多行 ...
- zabbix3.x添加华为(93069306)网络设备详解
转载自:https://www.cnblogs.com/yinzhengjie/p/6768006.html 前言: 欢迎加入:高级运维工程师之路 598432640 相信大家在看我的文章之前,也看过 ...
- H5使用codovar插件实现支付宝支付(支付宝APP支付模式,前端)
H5打包的app实现支付及支付宝支付,本章主要详解支付宝支付,微信支付请查看另一篇“H5使用codovar插件实现微信支付(微信APP支付模式,前端)” ps:本文只试用H5开发的,支付宝 APP支付 ...
- go语言问题集锦
==============================================beego框架=========================================== 1.使 ...
- oracle SQL多表查询
SQL多表查询 1.集合理论 1.1 什么是集合 具有某种特定性质的事物的总体. 集合的特性:无序性.互异性.确定性. 一个集合可以小到从一个表中取出一行中的一列. 1 ro ...
- Python第6天
主要内容: 递归:函数在内部自己调用自己,它的作用域没有return默认返回none 匿名函数 lambda ,与def的区别在于def可自行处理成元组,而lambda不行, func = lambd ...
- Java中ArrayList的删除元素总结
Java中循环遍历元素,一般有for循环遍历,foreach循环遍历,iterator遍历. 先定义一个List对象 List<String> list = new ArrayList&l ...
- hbase版本升级的api对比
前言 今天来介绍一下,hbase的2.1.0版本升级之后和1.2.6版本的api方法的一些不同之处. hbase的工具类 在介绍hbase的相关的java api之前,这里先介绍一下hbase的工具类 ...
- UI设计篇·入门篇·绘制简单自定义矩形图/设置按钮按下弹起颜色变化/设置图形旋转
Android的基本控件和图形有限,难以满足所有的实际需要和设计需求,好在Android给出了相对完善的图形绘制和自定义控件的API,利用这些API,可以基本满足设计的需求. 自定义图像和控件的方法: ...