• 案例


    案例

    for循环的底层实现原理

    point_count=0
    ls=range(0,10)
    while point_count<len(ls):
        print('.',end='')
        point_count+=1
    

    for循环实现loading原理

    import time
    s = 'loading'
    print(s,end='')
    for i in range (0,10):
        print('.',end='')
        time.sleep(1)
    

    while 嵌套

    案例1:

    while count<3:
    #     usr = input('usr: ')
    #     pwd = input('pwd: ')
    #     if usr == 'wq' and pwd == '123':
    #         print('登陆成功,进入操作界面。')
    #         while 1:
    #             cmd=input('cmd:')
    #             if cmd=='Q' or cmd=='q':
    #                 break
    #             print(cmd,'命令')
    #         break
    #     else:
    #         print ('登陆失败')
    #         count+=1
    

    案例2:

    # 1. 允许用户最多尝试3次
    # 2. 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序
    # 3. 如何猜对了,就直接退出
    # time = 0
    # while time < 3:
    #     age = input('请输入你的年龄:')
    #     age = int(age)
    #     if age == 18:
    #         print('zhengque')
    #         break
    #     elif age < 18:
    #         print('xiaole')
    #     else:
    #         print('打了')
    #     time += 1
    #     if time == 3:
    #         rp = input('输入Y或者Y继续游戏,输入N或N为推出游戏')
    #         if rp == 'Y' or rp == 'y':
    #             time = 0
    #         else:
    #             time = 9
    

    案例3:

    name = 'nick'
    pwd = '123'
    
    function_list = {0: 'kanpian', 1: 'dashan', 3: 'bamei'}
    
    count = 0
    
    while count < 3:
        username = input('>>>usrename: ')
        password = input('>>>password: ')
        re_password = input('>>>re_password: ')
    
        if username == name and password == pwd:
            if password == re_password:
                print('登录成功')
                while True:
                    print(f'请选择功能:{function_list}')
                    choice = input('>>>choice')
                    choice = int(choice)
                    print(f'你已经选择功能:{function_list[choice]}')
                break
            else:
                print('两次密码不一致')
        else:
            print('用户名或密码错误')
    
        count += 1
    
  • 相关阅读:
    sublime主题推荐
    安装JDK设置环境变量
    寻找灵感
    算法刷题3 PAT 1003 我要通过! (20 point(s))
    Java JDBC连接Mysql学习整理
    算法Day2-恶搞算法(网传88万代码生成)java实现
    算法刷题1:自测-1 打印沙漏 (20 point(s))
    Java I/O stream输入输出初整理
    Java this关键字初理解
    MD5加密算法
  • 原文地址:https://www.cnblogs.com/bruce123/p/10822643.html
Copyright © 2020-2023  润新知