Python验证码简单实现(数字和大写字母组成的4位验证码)
生活随笔
收集整理的這篇文章主要介紹了
Python验证码简单实现(数字和大写字母组成的4位验证码)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#數(shù)字和英文大寫字母的4位隨機(jī)數(shù)
def checkcode(): #def 定義方法 checkcode() 方法名()import random # 導(dǎo)入包checkcode = ""string = range(0,4)for i in string:current = random.randrange(0,3) #randrange隨機(jī)數(shù) 參數(shù)1<=隨機(jī)數(shù)<=參數(shù)2if current != i:temp = chr(random.randint(65, 90))else:temp = random.randint(0,9)checkcode += str(temp)return checkcode #此方法返回值:checkcode(變量)
while True:yanzhengma = checkcode()print("驗(yàn)證碼:",yanzhengma)user_in = str(input("請(qǐng)輸入驗(yàn)證碼:"))if user_in.lower() == yanzhengma.lower() :print("驗(yàn)證成功")breakelse :print("輸入錯(cuò)誤,請(qǐng)重新輸入!")
運(yùn)行結(jié)果
?
轉(zhuǎn)載于:https://www.cnblogs.com/Dzc163/p/8484009.html
總結(jié)
以上是生活随笔為你收集整理的Python验证码简单实现(数字和大写字母组成的4位验证码)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 可口的披萨,美味的披萨攻略
- 下一篇: Geany——Python配置