欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-26 14:29:56
import random# 生成随机验证码# 数字验证码check_code = ''for i in range(4): current = random.randint(1, 9) check_code += str(current)print(check_code)# 随机字母+数字验证码c ......
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)