流程控制--if条件
2024-10-19 02:17:59
/* if ....else .... */
[root@localhost test1]# vim .py
//ADD
#!/usr/bin/python if >:
print 'hello python'
print 'TRUE'
else:
print 'FALSE' [root@localhost test1]# python .py
FALSE
/* elif
如果if 不成立
elif 成立,则执行elif 如果if不成立
elif也不成立
则执行else
*/
[root@localhost test1]# vim .py
//ADD
#!/usr/bin/python if >:
print 'hello python'
print 'TRUE'
elif 'a':
print 'b'
else:
print 'FALSE' [root@localhost test1]# python .py
b
[root@localhost test1]# vim .py
//ADD
#!/usr/bin/python if >:
print 'hello python'
print 'TRUE'
elif :
print 'b'
else:
print 'FALSE' [root@localhost test1]# python .py
FALSE
/* 利用 raw_input()输入或输出的是 字符串, 始终 比整型数值大,所以当设计一个“分数脚本”时,没办法得出正确的结果 可以利用 int('')这样的形式,将字符串转换为整型。
*/
[root@localhost test1]# vim .py
//ADD
#!/usr/bin/python score = int(raw_input("Please input your score: "))
if score >= :
print 'A'
print 'excellent'
elif score >= :
print 'B'
print 'very good' elif score >=7:
print 'C'
print 'good'
else:
print 'D'
print 'Sorry,you failed.' [root@localhost test1]# python .py
Please input your score:
D
Sorry,you failed.
[root@localhost test1]# python .py
Please input your score:
C
good
[root@localhost test1]# python .py
Please input your score:
A
excellent
[root@localhost test1]# python .py
Please input your score:
B
very good
/* a.lower() -- 这个lower()函数能够把大写的东西变成小写 */
[root@localhost test1]# vim .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 .py
Please input [Yes/No]: Yes
programe is running...
[root@localhost test1]# python .py
Please input [Yes/No]: No
programe is exit
[root@localhost test1]# python .py
Please input [Yes/No]: yes
programe is running...
[root@localhost test1]# python .py
Please input [Yes/No]: no
programe is exit
[root@localhost test1]# python .py
Please input [Yes/No]: ddd
please input [Yes/No]
最新文章
- 屌丝程序员的梦想 (六) 我也写个开源CMS
- python 3 学习笔记 (三)
- ReferenceEquals和 == 和equals()的比较
- oracle中如何指定表字段自增
- boost总结之any
- Java基础--说集合框架
- 转义字符和ASCII
- SMO启发式选择
- Java中,当表单含有文件上传时,提交数据的如何读取
- POJ 2039 To and Fro
- mysql之 mysql 5.6不停机双主一从搭建(活跃双主一从基于日志点复制)
- codeM美团编程大赛初赛B轮D题
- iOS UIAlertController中加入倒计时,输入框,Swift讲解
- Parallel中分区器Partitioner的简单使用
- redis学习资料
- CentOS 7.3/Linux .net core sdk 安装
- 小程序数据绑定点赞效果切换(交流QQ群:604788754)
- 使用HttpWebRequest请求API接口以及其他网站资源
- Python 标准类库-日期类型之datetime模块
- IBM 3650 M3 yum upgrade后系统无法登陆问题
热门文章
- [Violet]天使玩偶
- [NOIP2015 TG D2T3]运输计划
- BZOJ1034 [ZJOI2008]泡泡堂BNB 【贪心】
- webpack散记
- 【枚举暴力】【UVA11464】 Even Parity
- [zabbix]zabbix分区表操作步骤
- 美国选举问题/完全背包/Knapsack
- 查看oracle日志文件切换频率
- sshSSH Secure Shell Client root用户无法登录解决办法
- [LeetCode] 14. Longest Common Prefix ☆