码迷,mamicode.com
首页 > 其他好文 > 详细

验证码生成

时间:2020-05-07 15:50:44      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:typeerror   ide   验证   cep   验证码   else   nal   __name__   range   

‘验证码生成‘
import numpy

def list_connect(*lists): #
result=[]
try:
for i in lists:
assert isinstance(i, list),‘{}不是列表‘.format(i)

# if type(result)!=type(i): #判断入参是否均为列表,如果不是则抛出异常,中断程序
# raise TypeError(‘参数{}不是列表而是{}!‘.format(i,type(i)))
except AssertionError as t:
print(t)
else: #若均为列表则进行列表连接操作
for i in lists:
for j in range(len(i)):
result.append(i[j])
return result
# for i in lists:
# for j in range(len(i)):
# result.append(i[j])
def identifying_code(n):
num=[x for x in range(48,58)]
high_letter=[x for x in range(65,91)]
low_letter=[x for x in range(97,123)]
original_code=list_connect(num,high_letter,low_letter)
print(original_code)
check_code=numpy.random.randint(0,len(original_code),size=n)
result=‘‘
for i in check_code:
result=result+chr(original_code[i])
print(result)

if __name__ == ‘__main__‘:
# l1=[1,2,3,4]
# l2=[5,6,7]
print(list_connect(‘21‘,‘213‘))
# lt=list_connect(l1,l2)
# print(lt)
identifying_code(6)
print(chr(97))

验证码生成

标签:typeerror   ide   验证   cep   验证码   else   nal   __name__   range   

原文地址:https://www.cnblogs.com/shineriver/p/12842872.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!