python随机验证码(数字和字母组合)

python学习网 2019-06-29 15:57:02
import random

# 生成随机验证码
# 数字验证码

check_code = ''

for i in range(4):
current = random.randint(1, 9)
check_code += str(current)

print(check_code)

# 随机字母+数字验证码

check_code = ''

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)
check_code += str(tmp)
print(check_code)
阅读(2256) 评论(0)