判断语句--if

缩进

逐行缩进

  if条件:

    代码1

    if条件2:

      代码2

语法

语法1:

  if条件:

    代码1

    代码2

    代码3

age = 60
is_beautiful = True
star = '水瓶座'

if age > 16 and age < 20 and is_beautiful and star == '水瓶座':
    print('我喜欢你,我们在一起吧!')

语法2:

  if条件:

    代码1

  else:

    代码1

age = 60
is_beautiful = True
star = '水瓶座'

if age > 16 and age < 20 and is_beautiful and star == '水瓶座':
    print('我喜欢你,我们在一起吧!')
else:
    print('阿姨好,我逗你玩儿呢,深藏功与名')
print('其他代码')

语法3:

  if条件:

    代码1

  elif:

    代码1

  else:

    代码1

score = 63

if score >= 90:
    print('优秀啊,小伙子!')
elif score >= 80:
    print('还可以吧!')
elif score >= 60:
    print('要努力了呀,小伙子')
else:
    print("滚啊!!!")

改进版:

score = input('请输入您的成绩:')
score = int(score)

if score >= 90:
    print('优秀啊,小伙子!')
elif score >= 80:
    print('还可以吧!')
elif score >= 70:
    print('要努力了呀,小伙子')
elif score >= 60:
    print('准备叫家长吧!')
else:
    print("滚啊!!!"

 

 

 

posted @ 2020-05-28 17:19  mini猪猪侠  阅读(270)  评论(0编辑  收藏  举报