zoukankan      html  css  js  c++  java
  • 运算符(and or not)的优先级运算与登录界面课后题优化版本

    废话不多说,直接上程序

    从最高优先级依次计算到最低优先级

    # and or not
    # print(2 > 1 and 1 < 4)
    print(2 > 1 or 1 < 4 or 2 < 3 and 9 > 6 and 3 < 2)
    # 优先级 ()> not > and > or
    # 上面程序运行如下
    # T or T or F
    # T or F
    # T
    View Code

    or 对数值的判断

    # x or y 若x为非零,则返回x
    print(1 or 2)
    print(1 or 133)
    print(0 or 2)
    View Code

     因为只有非零数转换为bool值是T,0转换为bool值时是F。

    演示:

    print(bool(1))
    print(bool(0))
    View Code

     

    and与or相反

    即x and y,x为真,则返回y。

    登录界面课后题优化版

    account = "admin"
    password = "admin"
    i=0
    while i <= 3:
        acc=input("请输入你的用户名")
        pas=input("请输入你的密码")
        if acc == account and pas == password :
           print("登陆成功")
           break
        else :
            i +=1
            if i == 1 :
                print("账号或密码错误,你还可以尝试2次")
            if i == 2 :
                print("账号或密码错误,你还可以尝试1次")
            if i == 3 :
                print("账号或密码错误,请明天再试")
                break
        continue
    View Code
  • 相关阅读:
    获取枚举Description的Name
    MVC 3 RequiredIf validator for multiple values
    js关闭页面(兼容浏览器)
    js实现复制到剪切板
    Reverse Integer
    303. Range Sum Query
    326.Power of Three
    328. Odd Even Linked List
    面试基础知识点
    javaSE学习博客与笔记
  • 原文地址:https://www.cnblogs.com/zly9527/p/11197792.html
Copyright © 2011-2022 走看看