python学习(​条件控制分支语句if)

#!/usr/bin/python
count =int(raw_input("Plz input your math record:"))
print count
if count >= 90:
   print ‘a‘
else:
   if count >=80:
       print ‘b‘
   else:
        if count >=70:
          print ‘c‘
        else:
           if count >=60:
             print ‘d‘
           else:
              print ‘no pass‘
print ‘End‘
sex =raw_input("Plz input your sex:")
print ‘sex‘, sex
if sex == ‘male‘:
        print ‘Gentlenman!‘
else:
        print ‘Lady!‘


条件控制分支语句if

判断条件

布尔表达式 非0既真


[root@ceshi ~]# python ceshi.py
True
False
[root@ceshi ~]# vim ceshi.py
#!/usr/bin/python
if True:
  print ‘True‘
else:
  print ‘False‘
if 0:
  print ‘True!‘
else:
  print ‘False‘


[root@ceshi ~]# cat ceshi.py
#!/usr/bin/python
if True:
  print ‘1True‘
else:
  print ‘1False‘
if 0:
  print ‘2True!‘
else:
  print ‘2False‘
if 1:
  print ‘3True!‘
else:
  print ‘3False‘
[root@ceshi ~]# python ceshi.py
1True
2False
3True!


条件判断:关系表达式

->

-<

-==

- !=

->=

-<=

record =int(raw_input(‘plz input your record ‘))
print record,
if record >= 90:
  print "Excellent!"
else:
  print " Good"
sex = raw_input(‘plz input your sex ‘)
if sex == ‘male‘:
 print ‘Man‘
else:
 print ‘Woman‘


逻辑表达式

-and

-or

-not

record =int(raw_input(‘plz input your record ‘))
print record,
if record >= 90:
  print "Excellent!"
else:
  print " Good"
sex = raw_input(‘plz input your sex ‘)
if sex == ‘male‘or sex == ‘m‘  or sex ==‘M‘ or sex ==‘man‘ or sex ==‘Man‘:
 print ‘Man‘
else:
 print ‘Woman‘


plz input your record 89

89  Good

plz input your sex m

Man


本文出自 “浩子的▁运维笔录ヽ” 博客,请务必保留此出处http://chenhao6.blog.51cto.com/6228054/1367459

python学习(​条件控制分支语句if),古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。