简单验证码生成

def check_code():
    import random
    checkcode = ""
    for i in range(4):
        current = random.randrange(0,4)
        if current != i:
            temp = chr(random.randint(65,90))
        else:
            temp = random.randint(0,9)
        checkcode += str(temp)
    return checkcode
while 1:
    code = check_code()
    print(code)
    user = input("请输入验证码:")
    if user == code:
        print("正确")
        break
    else:
        print("不正确")

猜你喜欢

转载自www.cnblogs.com/ShanCe/p/9302137.html