首页 > 其他 > 详细

流程控制之if判断

时间:2018-11-13 17:03:35      阅读:187      评论:0      收藏:0      [点我收藏+]

1.什么是if判断

     判断一个条件如果成立则...不成立则....

2.为何要有if判断

  让计算机能够像人一样具有判断的能力

3.如何用if判断

语法1

if 条件:

    code1

    code2

    code3

    .......

age = 19

if age != 18

  print("你好")

 

语法2

if 条件:

    code1

    code2

    code3

else:

    code1

    code2

    code3

# age=18
# sex=‘male‘
# wuzhong=‘human‘
# is_beautiful=True
#
# if age > 16 and age < 22 and sex == ‘female‘ and \
# wuzhong == ‘human‘ and is_beautiful:
# print(‘开始表白...‘)
# else:
# print(‘阿姨好,我逗你玩呢...‘)

 

语法3

if 条件1:

   if条件2:

            code1

            code2

           code3

    code1

     code2

 

    code3

 

# age = 18
# sex = ‘female‘
# wuzhong = ‘human‘
# is_beautiful = True
# is_successful = True
#
# if age > 16 and age < 22 and sex == ‘female‘ and wuzhong == ‘human‘ and is_beautiful:
# print(‘开始表白...‘)
# if is_successful:
# print(‘在一起‘)
# else:
# print(‘阿姨再见....‘)
# else:
# print(‘阿姨好,我逗你玩呢...‘)

 

 

  

 语法4

  if 条件1

       子代码块1

elif 条件2

       子代码块2

elif 条件3

       子代码块3

elif 条件4

       子代码块4

......

else:

   子代码块5

    

 

 

score = input(‘your score>>: ‘)
score=int(score)
if score >= 90:
print(‘优秀‘)
elif score >= 80:
print(‘良好‘)
elif score >= 70:
print(‘普通‘)
else:
print(‘很差‘)

 

流程控制之if判断

原文:https://www.cnblogs.com/lujiachengdelu/p/9952998.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!