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. C语言练手游戏-控制台输出一个会移动的坦克

    把C语言的知识融合起来做一个练手的小游戏项目,将自己掌握到的数据结构.数组.函数.宏定义等知识综合利用,增加对语法的熟练程度. 操作系统: windows 10 x64 编译IDE : VS2015 ...

  2. python魔法方法:__getattr__,__setattr__,__getattribute__

    python魔法方法:__getattr__,__setattr__,__getattribute__ 难得有时间看看书....静下心来好好的看了看Python..其实他真的没有自己最开始想的那么简单 ...

  3. Linux系统7z文件解压

    获取p7zip_16.02_src_all.tar.bz2 1.解压 tar jxvf p7zip_16.02_src_all.tar.bz2 2.编译 cd p7zip_16.02 make &am ...

  4. 解析如何在C语言中调用shell命令的实现方法【转】

    本文转自:http://www.jb51.net/article/37404.htm 1.system(执行shell 命令)相关函数 fork,execve,waitpid,popen表头文件 #i ...

  5. Python3学习笔记24-操作文件和目录

    环境变量 在操作系统中定义的环境变量,全部保存在os.environ这个变量中,可以直接查看: import os print(os.environ) 操作文件和目录 操作文件和目录的函数一部分放在o ...

  6. 功率 dbm 和 mw 的换算

    射频知识; 功率/电平(dBm):放大器的输出能力,一般单位为w.mw.dBm.dBm是取1mw作基准值,以分贝表示的绝对功率电平. 换算公式:电平(dBm)=10lgw5W  → 10lg5000  ...

  7. saltStack的event接口通过mysql数据库接收SaltStack批量管理日志

    event是一个本地的ZeroMQ PUB Interface,event是一个开放的系统,用于发送信息通知salt或其他的操作系统.每个event都有一个标签.事件标签允许快速制定过滤事件.除了标签 ...

  8. python下的socket常用方法举例

    python下的socket 1.简单的server和client端的socket代码 server.py: #!/usr/bin/env python #_*_ coding:utf-8 _*_ i ...

  9. convertToNodeSpace和convertToWorldSpace ---实际应用

    游戏中经常会用到一些变换: 游戏中武器和角色在一个layer上,为了效率,会考虑将bullet, effect和 PhysicsParticle分别放到不用的层上,对应的层上使用batchnode来提 ...

  10. Spring整合strus2简单应用总结

    本身strus2没接触过,所以这块学的一知半解,正常不整合的还没学(接着学) step: 1.创建web工程 2.在/WEB-INF/lib引入jar包 asm-3.3.jarasm-commons- ...