lesson1:Python 判断表达式应用
2016-01-05 23:41
344 查看
1/5/2016 判断表达式应用
Sample1:
salary=raw_input("please input your salary: ")
if salary>=10000:
print "you can eat twice!^_^"
elif 5000<= salary <10000:
print "you only can eat once!-_-"
else salary<5000:
print "you can not eat anything!#_#!"
issue1: salary 起始赋值为string类型,而后面的判断值为整型,需要在判断表达式前进行数据类型转换,salary=int(salary).
Issue2: salary 的str类型在未被转换成整型前,始终会执行第一个分支语句,那是因为string类型始终比int类型大.
Issue3: 在最后一个分支判断上,直接使用else语句,无需添加任何条件,若在else后添加条件,则会出现语法错误,而上例中else :=elif salary<5000:
Sample1:
salary=raw_input("please input your salary: ")
if salary>=10000:
print "you can eat twice!^_^"
elif 5000<= salary <10000:
print "you only can eat once!-_-"
else salary<5000:
print "you can not eat anything!#_#!"
issue1: salary 起始赋值为string类型,而后面的判断值为整型,需要在判断表达式前进行数据类型转换,salary=int(salary).
Issue2: salary 的str类型在未被转换成整型前,始终会执行第一个分支语句,那是因为string类型始终比int类型大.
Issue3: 在最后一个分支判断上,直接使用else语句,无需添加任何条件,若在else后添加条件,则会出现语法错误,而上例中else :=elif salary<5000:
相关文章推荐
- python3.5安装加密模块pycrypto
- Python系列之 - python文件操作
- python 并发执行之多线程
- 编写高质量代码--改善python程序的建议(四)
- python并发执行之多进程
- [Python标准库]functools——管理函数的工具
- 基于python的密码管理工具
- python知识-python操作MySQL数据库
- PYTHON 奇怪现象 记录下 WindowsError: [Error 2]
- 二、Python-----用户交互
- python 装饰器
- python学习之一:如何解决 lxml中找不到etree等问题
- numpy
- Learning Python(8)--Python Spider(爬虫)
- 一、Python-----之变量
- Python机器学习库scikit-learn实践
- leetcode之4Sum
- 机器学习算法与Python实践之(一)k近邻(KNN)
- 机器学习算法与Python实践之(五)k均值聚类(k-means)
- 机器学习算法与Python实践之(四)支持向量机(SVM)实现