python实现验证码登陆

import random
def creat():
    '''
    生成四位验证码
    '''
    checkcode = ""
    for i in range(4):
        current = random.randrange(0,4)
        if current == i:
            tmp = chr(random.randint(65,90))
        else:
            tmp = random.randint(0,9)
        checkcode += str(tmp)
    return checkcode
    
while True:
    password = creat()
    print("验证码是: %s" %password)
    user = input("请输入验证码(字母不区分大小写):")
    if password == user.upper():
        print("\033[1;32mpass\033[0m")
        break
    else:
        print("\033[1;31m验证码输入错误\033[0m")   

python实现验证码登陆_第1张图片

你可能感兴趣的:(玩python)