生成隨機驗證碼,並判斷用戶輸入的驗證碼是否正確dom
def identifying_code(): temp = "" for i in range(4): num = random.randrange(0, 4) if num == 1 or num == 3: rad1 = random.randrange(0, 9) temp = temp + str(rad1) elif num == 0 : rad2 = random.randrange(65, 91) temp = temp + chr(rad2) elif num == 2 : rad3 = random.randrange(97, 122) temp = temp + chr(rad3) print "隨機生成的驗證碼是:",temp return temp while True: s = identifying_code() code = raw_input("請輸入驗證碼(區分大小寫):") if code == s: print("恭喜你,驗證碼輸入正確~") break else: print("驗證碼輸入不正確,請從新輸入(已自動刷新驗證碼)")