《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.向函数传递信息 ...
随机推荐
- tp 执行sql 语句
$User = D('User'); $User->query('select * from think_user where status=1'); $User->execute('up ...
- 【Leetcode_easy】989. Add to Array-Form of Integer
problem 989. Add to Array-Form of Integer 参考 1. Leetcode_easy_989. Add to Array-Form of Integer; 完
- vue项目开发优化
1 按需引入ui组件 比如elementUI,不要直接在main.js中全局引入所有的组件,可以根据elementui的说明文件,按需引入 项目中的组件 2 异步引入路由组件 使用 { path:'/ ...
- Find minimum number of people to reach to spread a message across all people in twitter
Considering that I'ld would like to spread a promotion message across all people in twitter. Assumin ...
- 《ucore lab8》实验报告
资源 ucore在线实验指导书 我的ucore实验代码 练习1: 完成读文件操作的实现(需要编码) 题目 首先了解打开文件的处理流程,然后参考本实验后续的文件读写操作的过程分析,编写在sfs_inod ...
- 《ucore lab6》实验报告
资源 ucore在线实验指导书 我的ucore实验代码 练习1: 使用 Round Robin 调度算法(不需要编码) 题目 完成练习0后,建议大家比较一下(可用kdiff3等文件比较软件) 个人完成 ...
- php mqtt client
<?php /* phpMQTT */ class phpMQTT { private $socket; /* holds the socket */ private $msgid = 1; / ...
- e.g. i.e. etc. et al. w.r.t. i.i.d.英文论文中的缩写语
e.g. i.e. etc. et al. w.r.t. i.i.d. 用法:, e.g., || , i.e., || , etc. || et al., || w.r.t. || i.i.d. e ...
- 用pytorch1.0搭建简单的神经网络:进行多分类分析
用pytorch1.0搭建简单的神经网络:进行多分类分析 import torch import torch.nn.functional as F # 包含激励函数 import matplotlib ...
- 基于DNN的推荐算法总结
1.早期的算法 深度学习在CTR预估应用的常见算法有Wide&Deep,DeepFM等. 这些方法一般的思路是:通过Embedding层,将高维离散特征转换为固定长度的连续特征,然后通过多个全 ...