习题30 else 和 if. 附加练习3
来源:互联网 发布:会员数据分析公司 编辑:程序博客网 时间:2024/06/10 06:03
#coding=utf-8
#赋值
people = 20
cars = 19
buses =15
#赋值
people = 20
cars = 19
buses =15
if cars > people and buses < cars:
print "Take cars!!!!"
elif cars > people or buses > cars:
print "TAKE WHATEVER YOU WANT."
elif cars < people and buses < cars:
print "Better stay at home."
else:
print "Better to take the buses."
#note:
else:
XXXXXXX
else后面直接接:,然后缩进后,输出结果。
为什么不可以这样子:
if cars > people and buses = cars:
print "whatever"
原因: 布尔表达式是么有只有一个等号的。
elif只会运行它遇到的第一个True, 其他会忽略的。
0 0
- 习题30 else 和 if. 附加练习3
- 习题30 else 和 if
- 笨方法学Python 习题 30: Else 和 If
- 笨方法学习Python-习题30: Else 和 If
- if-else 语句练习
- Exercise 30: Else 和 If
- if 和else if
- IF 和else if
- if......if和if......else if......else if的区别
- 习题:if...else if...else的用法与注意事项
- if ...if...和if...else if...
- if...else... 和 if...else if... 或者 if...if... 和 if...else if... 有什么区别
- 练习27~30——判断,布尔值,if&else
- If语句(if…else 和 if…else if … else if … else)
- Learn Python the hard way. 习题30. If和else/elif
- SHELL笔记:-if-else,case练习
- if-else小练习(成绩划分)
- if和else if和switch
- LeetCode-Remove K Digits 去掉K位数字
- Problem C. gCampus Google APAC 2016 University Test Round A
- 【并发编程】当我们谈论线程安全时我们在谈论什么
- 算法粗略见解
- Linux make笔记
- 习题30 else 和 if. 附加练习3
- 一种基于中值滤波的轨迹纠偏方法和几点思考
- JAVA多线程实现的四种方式
- Leetcode 365
- Majority Element
- BufferInputStream与BufferOutputStream
- HDU-1274-展开字符串(dfs分段字符串处理)
- 对模拟form表单的疑问
- Linux动态库搜索路径