流程控制--if条件
2016-09-04 15:23
337 查看
/* if ....else .... */ [root@localhost test1]# vim 5.py //ADD #!/usr/bin/python if 1>2: print 'hello python' print 'TRUE' else: print 'FALSE' [root@localhost test1]# python 5.py FALSE
/* elif 如果if 不成立 elif 成立,则执行elif 如果if不成立 elif也不成立 则执行else */ [root@localhost test1]# vim 5.py //ADD #!/usr/bin/python if 1>2: print 'hello python' print 'TRUE' elif 'a': print 'b' else: print 'FALSE' [root@localhost test1]# python 5.py b [root@localhost test1]# vim 5.py //ADD #!/usr/bin/python if 1>2: print 'hello python' print 'TRUE' elif 0: print 'b' else: print 'FALSE' [root@localhost test1]# python 5.py FALSE
/* 利用 raw_input()输入或输出的是 字符串, 始终 比整型数值大,所以当设计一个“分数脚本”时,没办法得出正确的结果 可以利用 int('')这样的形式,将字符串转换为整型。 */ [root@localhost test1]# vim 6.py //ADD #!/usr/bin/python score = int(raw_input("Please input your score: ")) if score >= 90: print 'A' print 'excellent' elif score >= 80: print 'B' print 'very good' elif score >=70: print 'C' print 'good' else: print 'D' print 'Sorry,you failed.' [root@localhost test1]# python 6.py Please input your score: 30 D Sorry,you failed. [root@localhost test1]# python 6.py Please input your score: 70 C good [root@localhost test1]# python 6.py Please input your score: 92 A excellent [root@localhost test1]# python 6.py Please input your score: 83 B very good
/* a.lower() -- 这个lower()函数能够把大写的东西变成小写 */ [root@localhost test1]# vim 7.py //ADD #!/usr/bin/python yn = raw_input("Please input [Yes/No]: ") yn = yn.lower() if yn == 'y' or yn == 'yes': print "programe is running..." elif yn == 'n' or yn == 'no': print "programe is exit" else: print "please input [Yes/No]" [root@localhost test1]# python 7.py Please input [Yes/No]: Yes programe is running... [root@localhost test1]# python 7.py Please input [Yes/No]: No programe is exit [root@localhost test1]# python 7.py Please input [Yes/No]: yes programe is running... [root@localhost test1]# python 7.py Please input [Yes/No]: no programe is exit [root@localhost test1]# python 7.py Please input [Yes/No]: ddd please input [Yes/No]
相关文章推荐
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例 --转载
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- Python的流程控制 - if条件
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- JAVA学习(四):Java流程控制语句(顺序结构、if条件语句、switch条件语句、循环语句与跳转语句)
- [Shell]条件判断与流程控制:if, case, for, while, until
- JAVA学习(四):Java流程控制语句(顺序结构、if条件语句、switch条件语句、循环语句与跳转语句)
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- Java基础语法——运算符、流程控制语句、if条件语句
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- Linux shell 流程控制(条件if,循环for,while)
- [转]linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例