案例

案例

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
posted @ 2019-05-06 22:34  wanjiang  阅读(132)  评论(0编辑  收藏  举报