Python3练习题系列(01)
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)的更多相关文章
- Python3练习题系列(09)——物以类聚,人以群分
目标: 用类管理同类事物 解析: 用到“class”的编程语言被称作“Object Oriented Programming(面向对象编程)”语言.首先你需要做出“东西”来,然后你“告诉”这些东西去完 ...
- Python3练习题系列(10)——项目骨架构建
目标: 如何创建<项目“骨架”目录> 包含:项目文件布局.自动化测试代码,模组,以及安装脚本. 由于编写一个Python文件可以作为一个模块,一个带__init__.py的目录算一个包. ...
- Python3练习题系列(06)——各种符号总结
Python3中的各种符号总结 1关键字 import keyword print(keyword.kwlist, end='\t') ['False', 'None', 'True', 'and', ...
- Python3练习题系列(07)——列表操作原理
目标: 理解列表方法的真实含义. 操作: list_1.append(element) ==> append(list_1, element) mystuff.append('hello') 这 ...
- Python3练习题系列(08)——代码阅读方法及字典跳转表理解
问题:分析下面代码 cities['_find'] = find_city city_found = cities['_find'](cities, state) 分析过程: 一个函数也可以作为一个变 ...
- Python3练习题系列(05)——设计和调试规则
If 语句的常见规则 1. 每一个“if 语句”必须包含一个else: 2. 如果这个else 永远都不应该被执行到,因为它本身没有任何意义,那你必须在else 语句后面使用一个叫做die 的函数,让 ...
- Python3练习题系列(04)
题目: 制作一个游戏 知识点: 函数.if_elif_else, while, exit 游戏图谱: 游戏代码: from sys import exit def gold_room(): print ...
- Python3练习题系列(03)
题目: 思考While循环,看看它的特点是什么? 知识点: while循环 分析: 特点:while-loop(while 循环).while-loop 会一直执行它下面的代码片段,直到它对应的布尔表 ...
- Python3练习题系列(02)
题目: 思考循环结构,看看它是怎样运行的,对我们认识程序有何益处. 知识点: list, for-loop, range 练习代码: 练习1 the_count = [1, 2, 3, 4, 5] # ...
随机推荐
- 如何提交内核补丁--checkpatch.pl使用【转】
转自:https://blog.csdn.net/qq_29350001/article/details/52056667 转自: http://blog.csdn.net/ganggexiongqi ...
- oracle的读写分离实现
在MySQL作为应用系统的后台数据库时,我们常常见到这样的架构,一拖二.一拖三等等.这是用MySQL的读写分离技术,实现数据的写入和读取分别在不同的库上,提升了数据库服务能力. 同样,在Oracle作 ...
- linux添加定时任务crond
1.crontab –e:编辑当前定时任务 保存完重新crond : service crond restart 2. crontab用法 crontab –e : 修改 crontab 文件,如果文 ...
- 026_关于shell中的特殊变量$0 $n $* $@ $! $?
一. $n:获取当前执行的shell脚本的第N个参数,n=1..9,当n为0时表示脚本的文件名,如果n大于9,用大括号括起来like${10}. $*:获取当前shell的所有参数,将所有的命令行参数 ...
- nginx1.8.1反向代理、负载均衡功能的实现
nginx1.8.1 proxy 服务器192.168.8.40 web1 centos6.5 httpd2.2.15 web2 centos7.2 httpd2.4.6 1.代理功能的简单实现 ng ...
- JOptionPane类提示框常用方法总结
JOptionPane类封装了很多的方法,总结如下: 1.showMessageDialog 显示一个带有OK 按钮的模态对话框. 下面是几个使用showMessageDialog 的例子: Java ...
- Handler机制
目录结构 Android中的Handler的机制与用法详解,什么是Handler,如何传递 Message,传递 Runnable 对象,传递 Callback 对象,Handler 原理是什么?Ha ...
- 深度学习Bible学习笔记:第七章 深度学习中的正则化
一.正则化介绍 问题:为什么要正则化? NFL(没有免费的午餐)定理: 没有一种ML算法总是比别的好 好算法和坏算法的期望值相同,甚至最优算法跟随机猜测一样 前提:所有问题等概率出现且同等重要 实际并 ...
- linux 下 eclipse 安装
下载: 官网选择相应安装包下载,我这里下了tar.gz包 安装: tar xzvf eclipse-inst-linux64.tar.gz 设置环境变量 export JAVA_HOME=/usr/l ...
- 目标检测-yolo2
转载自:http://blog.csdn.net/qq_34784753/article/details/78825493 对于现在的最好的检测系统来说,yolo_v1 的问题主要出现在两方面,也就是 ...