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)