Exercise 29:If 是什么
来源:互联网 发布:网络推广威客 编辑:程序博客网 时间:2024/06/03 15:59
原文链接:http://learnpythonthehardway.org/book/ex29.html
下面你将进入的这个Python脚本向你介绍了 if 语句的使用。输入这些内容,并正确运行该脚本,然后我们来看看你的练习是否有了回报。
people = 20cats = 30dogs = 15if people < cats:print "Too many cats! The world is doomed!"if people > cats:print "Not many cats! The world is saved!"if people < dogs:print "The world is drooled on!"if people > dogs:print "The world is dry!"dogs += 5if people >= dogs:print "People are greater than or equal to dogs"if people <= dogs:print "People are less than or equal to dogs."if people == dogs:print "People are dogs."
输出结果如下:
E:\>python ex29.pyToo many cats! The world is doomed!The world is dry!People are greater than or equal to dogsPeople are less than or equal to dogs.People are dogs.
研究训练:
在这次的研究训练中,试着猜猜if语句有什么作用。在进行下一个练习之前试着用自己的话回答这些问题:1、你认为if对其下面的代码做了什么?
2、为什么if下面的代码需要4个空格的缩进?
3、如果不缩进会发生什么?
4、你能将Exercise 27中的其他布尔型表达式房子 if 遇见中吗?试一下。
5、看看如果改变 people ,cats ,dogs初始化值会发生什么。
学生遇见的常见问题:
+= 是什么意思?
答: x += 1 就等同于 x = x + 1 只是一种简写方式而已。你可以称这种为“按单位递增”操作符。 -= 操作符也是一样的,还有很多其他类似的表达式你在后面可以学习到。
0 0
- Exercise 29:If 是什么
- Exercise 30: Else 和 If
- exercise 29
- exercise 30 else and if 语句
- if 是什么东西啊
- if 是什么东西啊
- Python Exercise #29
- Exercise
- exercise
- Exercise
- exercise
- Python中if __name__ == "__main__"是什么作用
- benlamk if [ $# -eq 0 ]该语句是什么含义?
- Exercise 4.2 Exercise 4.3
- Yes, sitting too long can kill you, even if you exercise(坐太长时间对身体不好)
- 第12章:Continuous Latent Variables exercise 24-29
- Exercise------------ProgUseJava
- Exercise 1.16
- HTML解析组件HtmlAgilityPack使用
- C++之模板特化
- 【算法-排序之四】希尔排序
- myeclipse内存不足解决方法
- dtplayer编译运行说明
- Exercise 29:If 是什么
- 设置eclipse文件编码格式
- Fruit Ninja(水果忍者)游戏源代码下载、分析(上)---可运行Android,Ios,Window,Mac,Html5平台
- js中style、currentStyle、getComputed、runtimeStyle的区别
- 我的学习笔记(在C#里用MVC实现水晶报表)
- Hibernate和Ibatis比较
- shellcode搜集
- 【温故而知新】C和C++7:STL中的deque容器
- c语言字符串 数字转换函数大全