美文网首页
Python零基础2:条件判断与嵌套

Python零基础2:条件判断与嵌套

作者: Iphone60Plus | 来源:发表于2020-03-14 20:09 被阅读0次

    条件判断

    单向判断

    # 如果……就……
    stonenumber = 6
    if stonenumber >=6:
        print('你拥有了世界最大的力量')
    你拥有了世界最大的力量
    

    双向判断

    # 如果满足就执行if命令,否则就执行else命令
    stonenumber = 3
    if stonenumber >=6:
        print('你拥有了世界最大的力量')
    else:
        print('带我去见星云')
    

    多向判断

    # 满足那个条件,就执行那个条件的命令
    # if……elif……else 三者互斥
    #elif……后可不接else
    stonenumber = 0
    if stonenumber >=6:
        print('你拥有了世界最大的力量')
    elif 0 < stonenumber <= 5:
        print('需要绯红女巫破坏幻视的宝石')
    else:
        print('需要神奇女侠逆转未来')
    

    条件嵌套

    image.png
    historyscore = 26
    if historyscore >= 60:
        print('及格')
        if historyscore >= 80:
            print('优秀')
        else:
            print('一般般')
    else:
        print('不及格')
        if historyscore <= 30:
            print('学渣')
        else:
            print('加油努把力')
    不及格
    学渣
    

    相关文章

      网友评论

          本文标题:Python零基础2:条件判断与嵌套

          本文链接:https://www.haomeiwen.com/subject/oahnshtx.html