import random
def creat():
'''
生成四位驗證碼
'''
checkcode = ""
for i in range(4):
current = random.randrange(0,4)
if current == i:
tmp = chr(random.randint(65,90))
else:
tmp = random.randint(0,9)
checkcode += str(tmp)
return checkcode
while True:
password = creat()
print("驗證碼是: %s" %password)
user = input("請輸入驗證碼(字母不區分大小寫):")
if password == user.upper():
print("\033[1;32mpass\033[0m")
break
else:
print("\033[1;31m驗證碼輸入錯誤\033[0m")
python實現驗證碼登陸
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.