隨機驗證碼 python

2021-09-30 17:18:02 字數 810 閱讀 3080

'''

功能:隨機驗證碼

日期:01/22/2019

注意:randrange()返回乙個遞增集合的隨機數,使用它必須匯入random包

randint()返回乙個隨機數

chr()返回乙個字元,以整數為引數

'''import random

def check_code():

check_code = ''

for i in range(4):

current = random.randrange(0, 4)

if current != i:

temp = chr(random.randint(65, 90))

else:

temp = random.randint(0, 9)

check_code += str(temp)

return check_code

def main():

y_or_n = input("是否退出程式(y or n):")

while y_or_n == 'n':

code = check_code()

print ("驗證碼》" + code)

get_input = input(">>>")

if get_input.upper() == code:

print ("successfully!")

y_or_n = input("是否退出程式(y or n)")

if __name__ == '__main__':

main()

隨機驗證碼

function window,document if object.prototype.tostring.call options object object else this options.numarr 0,1,2,3,4,5,6,7,8,9 split this options.lette...

python 隨機生成驗證碼

首先隨機的生成數字或者字母肯定需要的是random模組。random是隨機數生成器。import random print random.random print random.randint 1,10 print random.randrange 1,11 以上的是最常見的隨機數生成方法,看看列印...

python隨機生成驗證碼

需要匯入pillow模組 from random import choice,randint from pil import image,imagedraw,imagefont,imagefilter class verifycode object 生成驗證碼模組 def init self,len...