《Python编程:从入门到实践》第五章 if语句 习题答案
#5.1
major = 'Software Engineering'
print("Is major =='Software Engineering'? I predict True.")
print(major=='Software Engineering') print("Is major =='Software Engineering'? I predict False.")
print(major=='Computer Science')
#5.2
print("--------------------------------------")
string_1='abc'
string_2='abc'
string_3='abcd'
print("Is string_1==string_2? ")
print(string_1==string_2)
print("Is string_2==string_3?")
print(string_2==string_3)
print("--------------------------------------")
print("Is string_1 == string_1.lower()?")
print(string_1==string_1.lower())
print("--------------------------------------")
print("这个部分实在过于简单和麻烦,略过!")
print("--------------------------------------")
print(True and False)
print(True and True)
print(False and False)
print(True or False)
print(True or True)
print(False or False)
print("--------------------------------------")
mobileInc = ['apple','xiaomi','huawei','oppo','vivo']
print('apple' in mobileInc)
print('coolpad' in mobileInc)
print('nokia' not in mobileInc) #5.3
alien_color = 'green'
if alien_color == 'green':
print("Great!You got 5 point!")
alien_color = 'red'
if alien_color == 'green':
print("Great!You got 5 point!")
print("------------------------------------")
#5.4
alien_color = 'green'
if alien_color == 'green':
print("Great!You got 5 point!")
else:
print("Excellent!You got 10 point!")
alien_color = 'red'
if alien_color == 'green':
print("Great!You got 5 point!")
else:
print("Excellent!You got 10 point!")
print("-----------------------------------------")
#5.5
alien_color = 'green'
if alien_color == 'green':
print("Great!You got 5 point!")
elif alien_color == 'yellow':
print("Excellent!You got 10 point!")
elif alien_color == 'red':
print("Oh,my god!You got 15 point!") alien_color = 'yellow'
if alien_color == 'green':
print("Great!You got 5 point!")
elif alien_color == 'yellow':
print("Excellent!You got 10 point!")
elif alien_color == 'red':
print("Oh,my god!You got 15 point!") alien_color = 'red'
if alien_color == 'green':
print("Great!You got 5 point!")
elif alien_color == 'yellow':
print("Excellent!You got 10 point!")
elif alien_color == 'red':
print("Oh,my god!You got 15 point!")
print("-----------------------------------------") #5.6
age = 33
if age < 2:
print("婴儿")
elif age>=2 and age<4:
print("蹒跚学步")
elif age>=4 and age<13:
print("儿童")
elif age>=13 and age<20:
print("青少年")
elif age>=20 and age<65:
print("成年人")
elif age>=65:
print("老年人") #5.7
favourite_fruits = ['apple','banana','orange']
if 'apple' in favourite_fruits:
print("You really like apples!")
if 'banana' in favourite_fruits:
print("You really like bananas!")
if 'orange' in favourite_fruits:
print("You really like orange!")
if 'watermalen' in favourite_fruits:
print("You really like watermalen!")
if 'grape' in favourite_fruits:
print("You really like grape!")
《Python编程:从入门到实践》第五章 if语句 习题答案的更多相关文章
- #Python编程从入门到实践#第四章笔记
#Python编程从入门到实践#第四章笔记 操作列表 1.遍历列表 使用for循环,遍历values列表 for value in values: print(value) 2.数字列表 使 ...
- python编程:从入门到实践----第五章>if 语句
一.一个简单示例 假设有一个汽车列表,并想将其每辆汽车的名称打印出来.遇到汽车名‘bmw’,以全大写打印:其他汽车名,首字母大写 cars=['audi','bmw','subaru','toyota ...
- 《Python编程从入门到实践》第二章_变量和简单数据类型
什么是变量呢? 举例: >>> message = "Hello,Python!" >>> print (message) Hello,Pyth ...
- Python:从入门到实践--第五章--if语句--练习
#1.编写一系列条件测试:将每个测试以及结果打印出来 car = '宝马' if car == "宝马": print("预测正确") print(car) e ...
- #Python编程从入门到实践#第三章笔记
列表简介 1.什么是列表 列表:由一系列按也顶顺序排列的元素组成.元素之间可以没有任何关系. 列表:用方括号[]表示,并用逗号分隔其中元素.名称一般为复数 2.访问元素 (1)列表是有序集合 ...
- Python编程从入门到实践笔记——异常和存储数据
Python编程从入门到实践笔记——异常和存储数据 #coding=gbk #Python编程从入门到实践笔记——异常和存储数据 #10.3异常 #Python使用被称为异常的特殊对象来管理程序执行期 ...
- Python编程从入门到实践笔记——文件
Python编程从入门到实践笔记——文件 #coding=gbk #Python编程从入门到实践笔记——文件 #10.1从文件中读取数据 #1.读取整个文件 file_name = 'pi_digit ...
- Python编程从入门到实践笔记——类
Python编程从入门到实践笔记——类 #coding=gbk #Python编程从入门到实践笔记——类 #9.1创建和使用类 #1.创建Dog类 class Dog():#类名首字母大写 " ...
- Python编程从入门到实践笔记——函数
Python编程从入门到实践笔记——函数 #coding=gbk #Python编程从入门到实践笔记——函数 #8.1定义函数 def 函数名(形参): # [缩进]注释+函数体 #1.向函数传递信息 ...
随机推荐
- [Google] 人和自行车匹配
2D平面上,有m个人(P),n辆自行车(B),还有空白(O)满足以下条件1.m < n. 2.不存在两个人,到同一辆自行车距离相等, 距离用abs(x1-x2) + abs(y1-y2)定义3. ...
- 【ARTS】01_42_左耳听风-201900826~201900901
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- Data - 数据思维 - 中篇
6 - 模型与框架 利用现有的成熟的理论.模型与框架,结合实际业务情况,搭建分析框架,尽量确保数据分析维度的完整性,结果的有效性及正确性. 营销理论模型:4P.用户使用行为.STP理论.SWOT等. ...
- 接口请求报错 504 Gateway Time-out
最近程序接口请求报了一个错误,如图 很明显的请求超时,以前也没出现过这个问题,突然就报了这个错,很懵. 百度之后网上说是nginx的问题,然后突然想起来,因为业务需要我在nginx里配了接口的转发. ...
- openfoam耦合liggghts安装
本次安装基于新安装的ubuntu18.04LTS桌面版系统,用户名为ubuntu,此前未安装其他软件(进行了系统提醒的更新),安装时间为2019年9月. 安装前需确认需要安装的OpenFOAM版本,C ...
- Python机器学习基础教程-第2章-监督学习之决策树集成
前言 本系列教程基本就是摘抄<Python机器学习基础教程>中的例子内容. 为了便于跟踪和学习,本系列教程在Github上提供了jupyter notebook 版本: Github仓库: ...
- DeviceEventEmitter React-Native 发送和接受消息(事件监听器)
A页面注册通知: import {DeviceEventEmitter} from 'react-native'; //… //调用事件通知 DeviceEventEmitter.emit('xxxN ...
- webpack的配置 @3.6.0
1.下载对应版本的webpack npm install webpack@3.6.0 -save --dev 2.新建webpack.config.js文件,目录结构↑ 3. >>webp ...
- LeetCode 442. 数组中重复的数据(Find All Duplicates in an Array) 17
442. 数组中重复的数据 442. Find All Duplicates in an Array 题目描述 Given an array of integers, 1 ≤ a[i] ≤ n (n ...
- LeetCode 232. 用栈实现队列(Implement Queue using Stacks) 4
232. 用栈实现队列 232. Implement Queue using Stacks 题目描述 使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部. pop() -- 从 ...