python学习日记_第十二天(ex29~30)
2016-02-02 08:36
459 查看
L29 如果(If)
If语句的练习:
L30 Else 和 If
If语句的练习:
#coding:utf-8 people = 20 cats = 30 dogs = 15 #下面这个用还有not的符合布朗式做判断条件 if not (1 == 10 or 3 == 4): 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 += 5 if 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." ''' 1.你认为 if 对于它下一行的代码做了什么? 判断是否执行。 2.为什么 if 语句的下一行需要 4 个空格的缩进? 这个python的格式,用来判断if控制的范围。 3.如果不缩进,会发生什么事情? 会报错 4.把习题 27 中的其它布尔表达式放到``if语句``中会不会也可以运行呢?试一下。 如果把变量 people, cats, 和 dogs 的初始值改掉,会发生什么事情? 可以。更改变量使if条件变化,执行的内容也会变化。 '''
L30 Else 和 If
#coding:utf-8 people = 30 cars = 40 buses = 50 if cars > people: print "We should take the cars." elif cars < people: print "We should not take the cars." else: print "We can't decide." if buses > cars: print "That's too many buses." elif buses <cars: print "Maybe we could take the buses." else: print "We still can't decide."
相关文章推荐
- Python 10.5 hashlib
- leetcode之Serialize and Deserialize Binary Tree
- 简介Python设计模式中的代理模式与模板方法模式编程
- 举例讲解Python中的Null模式与桥接模式编程
- Python的组合模式与责任链模式编程示例
- Python生成随机数的方法
- scrapy高级用法之自动分页
- python中json数据中文编码显示的问题
- python 线程
- Win7下安装Python图像处理库PIL
- 一个倒排索引(inverted index)的python实现
- python使用代理访问服务器
- Python 10.4 struct
- python学习笔记Day3
- 《笨办法学Python》 第30课手记
- Python装饰器
- leetcode之Sort List
- [python] python抓取有道词典并格式化输出的程序
- python请求服务器时如何隐藏User-Agent
- python操作mysql数据库