zoukankan      html  css  js  c++  java
  • 第一章 循环语句

    控制语句 if...else

    if 条件:

        代码

    else:

        print(‘ ’)

    if ...else...

    if 条件:

        代码

    elif 条件:

        代码

    elif 条件:

        代码

    else:

        代码

    While 循环

    count = 0

    while count<=100:

        print("loop",count)

        count+=1

    死循环

    count=0

    while True:

        print('aisfioasudfiaus',count)

        count+=1

    循环终止语句

    break

    count=0

    while count<100:

        print('loop', count)

        if count ==5:

        break

        count+=1

    print('-----out of while loop ------')

    continue

    count=0

    while count <=100:

    count+=1

        if count>5 and count <95:

           continue

        print("loop", count)

    print("----out of while loop ----")

    while ... else ...

    count=0

    while <=5:

        count+=1

        print("loop",count)

    else:

        print('')

    print("-----------")

    作业:

    猜年龄

    age_of_oldboy=8

    age=input('请输入年龄>>: ')

    if age==age_of_oldboy:

        print('正确')

        break

    else:

        print('错误,请重新输入)

    age=input('请输入年龄>>: ')

    if age==age_of_oldboy:

        print('正确')

        break

    else:

        print('错误,请重新输入)

    age=input('请输入年龄>>: ')

    if age==age_of_oldboy:

        print('正确')

        break

    else:

        print('错误超过三次,退出)

    count=0
    age_of_oldboy=8

    while count<3:
    age = int(input('请输入年龄>>: '))
    if age == age_of_oldboy:
    print('正确')
    break
    else:
    print('错误')
    count += 1

    if count==3:
    agent=input('错误次数超过三次,继续按y,否则按n')
    if agent== 'y'or agent == 'Y':
    count=0
    continue
    elif agent == 'N' or agent == 'n':
    break



    登陆接口
    用户3次认证失败后,退出程序,再次启动程序尝试登陆时,还是锁定状态(用户锁定状态存在文件里)
    dic={'user1':{'psw':'123','count':0},
    'user2':{'psw':'123','count':0},
    'user3':{'psw':'123','count':0},
    }
    while True:
    name=input('请输入用户名>: ')
    if not name in dic:
    print('请重试')
    continue
    with open('user.txt','r') as read_f:
    bb=read_f.read().splitlines()
    if name in bb:
    print('账户已锁定')
    continue


    psw=input('请输入密码>: ')
    if dic[name]['count'] >2:
    print('锁定')
    with open('user.txt', 'a+') as write_f:
    write_f.write(name)
    write_f.write(' ')
    break


    if psw ==dic[name]['psw']:
    print('登陆成功')
    break
    else:
    print('请重试')
    dic[name]['count']+=1
    continue


  • 相关阅读:
    数据结构与算法之二叉查找树精简要点总结
    数据结构与算法之并查集的精简要点总结
    数组嵌套实现哈希函数的数据分片应用
    InfluxDB 写入&查询 Qt工程(C++ 客户端 API)
    关于Maven中<packaging>产生的一些问题
    Spring Boot:The field file exceeds its maximum permitted size of 1048576 bytes
    Npm管理命令
    ES6转ES5(Babel转码器)
    IOC容器中的依赖注入(一)
    Nginx常用部分命令
  • 原文地址:https://www.cnblogs.com/mayicai/p/8921397.html
Copyright © 2011-2022 走看看