# !/usr/bin/env python # -*-coding:utf-8-*- import Span style= "color: #000000;" > Randomli =[] for i in Range (6): # loop a few times, just Represents the generation of several verification codes num = Random.randrange (65,95) # 65-91 random Print Range, (65<=num<91) c=CHR (num) li.append (c) Result = "" . Join (LI) # The meta in the list Must be a string print (Result)
#生成的验证码第二位和第四位是数字
li1=[] forIinchRange (6): ifi = = 2ori = = 4:#here is the definition of locationnum = Random.randrange (0,10) li1.append (num)#because the join concatenation must be a string, the conversion is done here Else: Num1= Random.randrange (65,91) C=CHR (NUM1)#chr () function function: Converts a number to a letterLi1.append (c) RET="". Join (LI1)Print(ret)
#随机生成数字和字母
#!/usr/bin/env python#-*-coding:utf-8-*-ImportRandomli2=[] forIinchRange (6): num2=random.randrange (0,5) ifnum2 = = 2ornum2 = = 4:#This is defined as a location.num = Random.randrange (0,10) li2.append (num)#because the join concatenation must be a string, the conversion is done here Else: Num1= Random.randrange (65,91) C=chr (NUM1) Li2.append (c) RET="". Join (LI2)Print(ret)
Random module (captcha applet)