/* 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]

流程控制--if条件的更多相关文章

  1. python 流程控制(条件语句)

    1,python流程控制单条件基本语句 2,python流程流程多条件控制语句 3,三元运算 1,python流程控制单条件基本语句 if 判断条件: 执行语句…… else: 执行语句…… 判断条件 ...

  2. java基础 流程控制和条件语句,循环语句

    顺序结构 程序的顺序结构: 如果代码里没有流程控制,程序是按照书写的格式从上而下一行一行执行的, 一条语句执行完之后继续执行下一条语句,中间没有判断和跳转,直到程序的结束. if语句 if语句使用bo ...

  3. linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例 --转载

    http://www.cnblogs.com/chengmo/archive/2010/10/14/1851434.html nux shell有一套自己的流程控制语句,其中包括条件语句(if),循环 ...

  4. [转]linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例

    原文链接:http://www.cnblogs.com/chengmo/archive/2010/10/14/1851434.html linux shell有一套自己的流程控制语句,其中包括条件语句 ...

  5. shell编程 之 流程控制(条件语句和循环语句)

    1 if ...else... 基本格式: if condition then commend else commend fi 当然也可以写到一行,用[ ]表明边界,用:表示分行.比如: if [ $ ...

  6. 廖雪峰Java1-3流程控制-3条件判断

    1.if条件判断的格式 if (条件) { 代码块 } if (条件) { 代码块1 } else { 代码块2 } if (条件1) { 代码块1 } else if { 代码块2 } else { ...

  7. Python流程控制-2 条件判断

    条件判断 条件判断是通过一条或多条判断语句的执行结果(True或者False)来决定执行的代码块. 在Python语法中,使用if.elif和else三个关键字来进行条件判断. if语句的一般形式如下 ...

  8. Go语言的流程控制(条件,选择,控制,跳转,闭包)

    1.条件语句: 跟C和python又不同了Go的if -else是这样的 if a<5{ return 0 } else { reutrn 1 } 1.条件不需要用括号括起来 2.左边的花括号必 ...

  9. ansible-playbook流程控制-when条件判断

    1. ansible-playbook添加判断     when相当于shell脚本里的if 判断,when语句就是用来实现这个功能的,它是一个jinja2的语法,但是不需要双大括号,用法很简单  1 ...

随机推荐

  1. Codeforces ZeptoLab Code Rush 2015 D.Om Nom and Necklace(kmp)

    题目描述: 有一天,欧姆诺姆发现了一串长度为n的宝石串,上面有五颜六色的宝石.他决定摘取前面若干个宝石来做成一个漂亮的项链. 他对漂亮的项链是这样定义的,现在有一条项链S,当S=A+B+A+B+A+. ...

  2. (转) Parameter estimation for text analysis 暨LDA学习小结

    Reading Note : Parameter estimation for text analysis 暨LDA学习小结 原文:http://www.xperseverance.net/blogs ...

  3. [Violet]蒲公英

    description 在线询问区间众数. data range \[n\le 40000,m\le 50000,a_i\le 10^9\] solution 自己分块不行于是\(\%\)了\(yyb ...

  4. 控制Docker Compose的启动顺序的一个思路

    起源 守护进程daemon 从守护进程的角度看Docker Compose Docker的解决方案 思路 代码 结果 起源 Docker Compose提供了一个depends_on参数. https ...

  5. POJ3525:Most Distant Point from the Sea——题解

    http://poj.org/problem?id=3525 题目大意:给一个逆时针序列的多边形点集,求其中可以画的最大半径的圆的半径. —————————————————————— 二分枚举半径长度 ...

  6. 实例——简单的Samba共享

    服务端配置 # 临时停止iptables service iptables stop # 临时禁用SELinux setenforce 0 # 禁止iptables开机自动启动 chkconfig i ...

  7. 背景建模技术(六):帧处理(FrameProcessor)模块

    前面几篇文章简单介绍了BgsLibrary的入口函数.视频分析和视频捕获模块,本文将简单介绍帧处理模块,即对每一帧进行处理的函数,也就是真正调用背景建模算法的接口处. 下面贴出源码供大家分析: #in ...

  8. Random Numbers Gym - 101466K dfs序+线段树

    Tamref love random numbers, but he hates recurrent relations, Tamref thinks that mainstream random g ...

  9. array_value

    <?php $a=array("Name"=>"Bill","Age"=>"60","Cou ...

  10. php中error_reporting

    error_reporting(255);是列出所有提示error_reporting(0);是不显示所有提示建议使用error_reporting(7);只显示严重错误1 E_ERROR 致命的运行 ...