验证码生成判断

import random

def code_creat():
    codes = ''
    """创建四位验证码"""
    for n in range(4):
        current = random.randrange(0,4)
        if current != n:
            code_o = str(random.randint(0,9))
        else:
            code_o = chr(random.randint(65,90))
        codes += code_o
    return codes

while True:
    code = code_creat()
    print(code)
    s = input("请输入验证码:")
    if s.lower() == code.lower():
        x = 'yes'
        print('正确!')
        break
    else:
        print('验证码错误!')

 

posted @ 2019-07-23 20:01  pywhy  阅读(140)  评论(0编辑  收藏  举报