python学习笔记之分支结构、三元表达式、逻辑运算符

分支结构

  • 单分支

    # if一般用于判断/选择的场景
    # 90以上优秀
    score = 95
    if score > 90:
        print('优秀')# 双分支
  • 双分支

    # if...else
    # 90以上优秀,90一下良好
     score = 95
     if score > 90:
         print('优秀')
     else:
         print('良好')
  • 多分支

    # if...elif...elif...else
    # if...if...if...if
    # 90以上优秀,90-70良好,70以下不及格
    score = 95
    if score > 90:
        print('优秀')
    elif score > 70:
        print('良好')
    else:
        print('及格')
        score = 95
    
    if score > 90:
        print('优秀')
    if score > 70 and score < 90: # 同时满足
        print('良好')
    if score < 60:
        print('及格')

猜你喜欢

转载自www.cnblogs.com/XuChengNotes/p/11235718.html