import random
flag = 1
try_=0
while (flag):
try_ +=1
yan = ""
for i in range(0,4):
cun=random.randrange(1,4)
if cun==i:
tmp=chr(random.randint(65,90))
else:
tmp=random.randrange(0,9)
yan+=str(tmp)
print(yan)
var=input("请输入验证码:")
if var == yan:
print('验证成功')
break
else:
print("验证失败")
if try_ == 3:
print("输入次数超3过次,请过会儿再试...")
break
孰能生巧