#随机生成由英文字符和数字组成的4位验证码
import random
from time import sleep
lst1=[]
cishu=0
def shuzi():
lst1.append(random.randint(0,9))
def xiaoxieyingwenzimu():
lst1.append(random.choice(['a','b','c','d','e','f','g','h','i','j','k','l',
'm','n','o','p','q','r','s','t','u','v','w','x','y','z']))
def daxieyingwenzimu():
xiaoxie=random.choice(['a','b','c','d','e','f','g','h','i','j','k','l',
'm','n','o','p','q','r','s','t','u','v','w','x','y','z'])
daxie=xiaoxie.upper() #转成大写的
lst1.append(daxie)
def yanzhengmaliucheng():
zifusuiji=random.randint(1,3)
#每一位的字符随机,1代表数字,2代表小写英文字母,3代表大写英文字母
while True:
while cishu!=4:
zifusuiji=random.randint(1,3)
#每一位的字符随机,1代表数字,2代表小写英文字母,3代表大写英文字母
if zifusuiji==1:shuzi()
if zifusuiji==2:xiaoxieyingwenzimu()
if zifusuiji==3:daxieyingwenzimu()
cishu+=1
lst1= str(lst1).replace("'", "").replace(",", "").replace("[", "").replace("]", "").replace(" ", "")
print("\n\t\t\t\t┎━━━━━┒\n\t\t\t验证码:┃ {} ┃\n\t\t\t\t┖━━━━━┚".format(lst1))
lst2=input("\n\t\t请输入图中的验证码:")
if lst2==lst1:
sleep(0.5)
print("\n\t\t\t\t验证中",end="")
sleep(0.5)
print(".",end="")
sleep(0.3)
print("...",end="")
sleep(0.2)
print("......",end="")
print("\n\n\t\t\t\t验证成功!")
break
else:
print("\n\n\t\t\t\t请输入正确的验证码!")
cishu=0
lst1=[]