验证码生成
1. 纯数字验证码(4位)
import random verificationcode = '' for i in range(4): current = random.randint(0,9) verificationcode+=str(current) print(verificationcode)
2. 数字字母混合验证码(4位)
import random verificationcode = '' for i in range(4): current = random.randint(0,4) if current == i: #当循环与随机数相等则产生字母 t_code = chr(random.randint(65,90)) #chr将数字转换为ascii码中的字母 else: t_code = random.randint(0,9) verificationcode+=str(t_code) print(verificationcode)
博主小学未毕业,请勿口喷!