2018-06-13

题目:

根据用户回答做出相应的判断,完成一个“回答-判断”的小游戏

Python3知识点:

if, else, elif

实例代码:

print("You enter a dark room with two doors. Do you go through door #1 or door #2?")
door = input("> ")
if door == '':
print("There's a giant bear here eating a cheese cake. What do you do?")
print("1. Take the cake.")
print("2. Scream at the bear.")
bear = input('> ')
if bear == "":
print("The bear eats your face off. Good job!")
elif bear == '':
print("The bear eats your legs off. Good job!")
else:
print("Well, doing %s is probably better. Bear runs away." % bear)
elif door == "":
print("You stare into the endless abyss at Cthulhu's retina.")
print('1. Blueberries.')
print('2. Yello jacket clothespins.')
print('3. Understanding revolvers yelling melodies.')
insanity = input('> ')
if insanity == '' or insanity == '':
print("Your body survives powered by a mind of jello. Good job!")
else:
print('The insanity rots your eyss into a pool of muck. Good job!')
else:
print("You stumble around and fall on a knife and die. Good job!")

代码运行结果:

输入#1

You enter a dark room with two doors. Do you go through door #1 or door #2?
> 1
There's a giant bear here eating a cheese cake. What do you do?
1. Take the cake.
2. Scream at the bear.
> 2
The bear eats your legs off. Good job!
You enter a dark room with two doors. Do you go through door #1 or door #2?
> 1
There's a giant bear here eating a cheese cake. What do you do?
1. Take the cake.
2. Scream at the bear.
> 1
The bear eats your face off. Good job!
You enter a dark room with two doors. Do you go through door #1 or door #2?
> 1
There's a giant bear here eating a cheese cake. What do you do?
1. Take the cake.
2. Scream at the bear.
> 3
Well, doing 3 is probably better. Bear runs away.

输入#2

You enter a dark room with two doors. Do you go through door #1 or door #2?
> 2
You stare into the endless abyss at Cthulhu's retina.
1. Blueberries.
2. Yello jacket clothespins.
3. Understanding revolvers yelling melodies.
> 3
The insanity rots your eyss into a pool of muck. Good job!
You enter a dark room with two doors. Do you go through door #1 or door #2?
> 2
You stare into the endless abyss at Cthulhu's retina.
1. Blueberries.
2. Yello jacket clothespins.
3. Understanding revolvers yelling melodies.
> 2
Your body survives powered by a mind of jello. Good job!

输入#其它

You enter a dark room with two doors. Do you go through door #1 or door #2?
> #
You stumble around and fall on a knife and die. Good job!

来自《笨办法学Python》

Python3练习题系列(01)的更多相关文章

  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练习题系列(07)——列表操作原理

    目标: 理解列表方法的真实含义. 操作: list_1.append(element) ==> append(list_1, element) mystuff.append('hello') 这 ...

  5. Python3练习题系列(08)——代码阅读方法及字典跳转表理解

    问题:分析下面代码 cities['_find'] = find_city city_found = cities['_find'](cities, state) 分析过程: 一个函数也可以作为一个变 ...

  6. Python3练习题系列(05)——设计和调试规则

    If 语句的常见规则 1. 每一个“if 语句”必须包含一个else: 2. 如果这个else 永远都不应该被执行到,因为它本身没有任何意义,那你必须在else 语句后面使用一个叫做die 的函数,让 ...

  7. Python3练习题系列(04)

    题目: 制作一个游戏 知识点: 函数.if_elif_else, while, exit 游戏图谱: 游戏代码: from sys import exit def gold_room(): print ...

  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. Device Tree常用方法解析【转】

    转自:https://blog.csdn.net/airk000/article/details/21345159 Device Tree常用方法解析 Device Tree在Linux内核驱动中的使 ...

  2. Websphere MQ Cluster

    大纲: 1.什么是集群 2.建立一个基本的集群 3.DISPLAY命令 4.负载均衡 5.高级配置和管理 6.答疑 7.关于文章.红宝书等 一. 什么是集群       集群就是Websphere M ...

  3. java 基础(转自索宁)

    一.方法函数 函数也称为方法,就是定义在类中的具有特定功能的一段独立代码.用于定义功能,提高代码的复用性. 函数的特点1> 定义函数可以将功能代码进行封装,便于对该功能进行复用:2> 函数 ...

  4. select 不要 用*

    背景 说实在的,这有什么好记录的呢.记录这个有啥用,真是技术人员的吹毛求疵.说起来,就是给人装有用吧.既然记录了,也想个相关的段子吧.曾经有个同事写了个sql,效率极差,来了个女同事,竟然解决了,问题 ...

  5. Vue.js——循环(Java、JSTL标签库、数据库)

    一.Vue.js循环 Vue.js循环要使用 v-for 指令. v-for 指令需要以 student in StudentList 形式的特殊语法使用, StudentList 是源数据数组并且s ...

  6. centos6.8系统安装 Hadoop 2.7.3伪分布式集群

    安装 Hadoop 2.7.3 配置ssh免密码登陆 cd ~/.ssh                       # 若没有该目录,请先执行一次ssh localhost ssh-keygen - ...

  7. Android通讯:短信

    Android通讯之短信功能实现: 使用android.telephony.SmsManager对象,可以发送短信和彩信.// 构造回调函数,短信发送结束后,会发出对应的Intent请求Intent ...

  8. Day6-------------ext4文件系统

    1.cp /etc/passwd /sdb6 把/etc/passwd的内容写入 sdb6 写入过程:日志------------>刷到硬盘 2.ext4已经有点过时 xfs:可存海量数据 bt ...

  9. Android动态控制状态栏显示和隐藏

    记得之前有朋友在留言里让我写一篇关于沉浸式状态栏的文章,正巧我确实有这个打算,那么本篇就给大家带来一次沉浸式状态栏的微技巧讲解. 其实说到沉浸式状态栏这个名字我也是感到很无奈,真不知道这种叫法是谁先发 ...

  10. ORACLE与SQLSERVER数据转换

    前言: 将SQLServer数据库中的表和数据全量导入到Oracle数据库,通过Microsoft SqlServer Management Studio工具,直接导入到oracle数据库,免去了生成 ...