其他分享
首页 > 其他分享> > 逻辑运算符补充与循环

逻辑运算符补充与循环

作者:互联网

逻辑运算符知识补充

amd

or

循环结构

while

while True:
    name = input('name>>>:')
    birthday = input('birthday>>>:')
    if name == 'batman' and birthday == '2.19':
        print('欢迎蝙蝠侠')
    else:
        print('错误')

结束循环

全局标志位

1

v1 = 1 or 3
v2 = 1 and 3
v3 = 0 and 2 and 1
v4 = 0 and 2 or 1
v5 = 0 and 2 or 1 or 4
v6 = 0 or False and 1
v1=1
v2=3
v3=0
v4=1
v5=1
v6=False

2

while count < 4:
    name = input('name>>>:')
    birthday = input('birthday>>>:')
    if name == 'batman' and birthday == '2.19':
        print('欢迎少爷')
        break
    else:
        print('错误')
        count += 1
else:
    print('账号已锁定')

3

flag = True
while flag:
    name = input('name>>>:')
    birthday = input('birthday>>>:')
    if name == 'batman' and birthday == '2.19':
        while flag:
            aa = input('输入指令>>>:')
            bb = '正在执行您的指令:%s'
            print(bb % aa)
            if aa == 'q':
                flag = False
            else:
                continue
    else:
        print('错误')

4

flag = True
while flag:
    aa = input('输入y重新开始:')
    if aa == 'q':
        flag = False
    elif aa == 'y':
        count = 1
        while count < 4:
            age = input('age>>>:')
            if age == '18':
                print('恭喜你!!!回答正确!!!')
                flag = False
                break
            else:
                print('错误')
                count += 1

标签:逻辑,name,birthday,运算符,while,循环,print,input,True
来源: https://www.cnblogs.com/riuqi/p/16402011.html