Python验证码简单实现(数字和大写字母组成的4位验证码)
生活随笔
收集整理的這篇文章主要介紹了
Python验证码简单实现(数字和大写字母组成的4位验证码)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#數字和英文大寫字母的4位隨機數
def checkcode(): #def 定義方法 checkcode() 方法名()import random # 導入包checkcode = ""string = range(0,4)for i in string:current = random.randrange(0,3) #randrange隨機數 參數1<=隨機數<=參數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("驗證碼:",yanzhengma)user_in = str(input("請輸入驗證碼:"))if user_in.lower() == yanzhengma.lower() :print("驗證成功")breakelse :print("輸入錯誤,請重新輸入!")
運行結果
?
轉載于:https://www.cnblogs.com/Dzc163/p/8484009.html
總結
以上是生活随笔為你收集整理的Python验证码简单实现(数字和大写字母组成的4位验证码)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 可口的披萨,美味的披萨攻略
- 下一篇: Geany——Python配置