题目:

制作一个游戏

知识点:

函数、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. script & scriptreplay

    script是什么 scirpt就是一个命令,可以制作一份记录输出到终端的记录.对于那些想要真实记录终端会话的人来说,这很有用.该记录可以保存并在以后再打印出来. 怎么用 默认情况下,我们可以通过在终 ...

  2. C语言表驱动法编程实践

    数据压倒一切.如果选择了正确的数据结构并把一切组织的井井有条,正确的算法就不言自明.编程的核心是数据结构,而不是算法. ——Rob Pike  说明 本文基于这样的认识:数据是易变的,逻辑是稳定的. ...

  3. mysql启动时报错:Starting MySQL... ERROR! The server quit without updating PID file (/opt/mysql/data/mysql.pid)

    mysql启动报错Starting MySQL... ERROR! The server quit without updating PID file (/opt/mysql/data/mysql.p ...

  4. ES系列十三、Elasticsearch Suggester API(自动补全)

    1.概念 1.补全api主要分为四类 Term Suggester(纠错补全,输入错误的情况下补全正确的单词) Phrase Suggester(自动补全短语,输入一个单词补全整个短语) Comple ...

  5. XmlDocument根据节点的属性值获取节点

    string targetParm = string.Format("STUDENTS/STUDENT[@NO='{0}']", targetValue);//生成目标获取节点的参 ...

  6. DDMS调试工具

    ADT给我们提供了一个非常方便的调试工具,那就是DDMS.使用这个工具,代码调试工作也变得简单起来.我们只需要单击Eclipse界面右上方的DDMS按钮就可以切换到DDMS界面了,如图2-31所示. ...

  7. Expm 8_1 区间划分问题

      [问题描述] 给定一组报告,其中的每个报告设置了一个开始时间si和结束时间fi.设计与实现一个算法,对这组报告分配最少数量的教室,使得这些报告能无冲突的举行. package org.xiu68. ...

  8. GitHub上README.md的简单介绍

    1.编辑README文件 大标题(一级标题):在文本下面加等于号,那么上方的文字就变成了大标题,等于号的个数无限制,但一定要大于0 大标题 ==== 中标题(二级标题):在文本下面加下划线,那么上方的 ...

  9. pyspark遇到报错:_PYSPARK_DRIVER_CONN_INFO_PATH

    1.  环境 : centos,启动pyspark,执行如下python命令: import pyspark from pyspark import SparkContext from pyspark ...

  10. C++ code:数组初始化

    具有初始化的数组定义,其元素个数可以省略,即方括号中的表达式可以省略.这时候,最后确定的元素个数取决于初始化值的个数.例如: #include<iostream> using namesp ...