import random
while True:
code = ‘‘
for i in range(4):
current = random.randrange(0,4)
if current == i:
temp = chr(random.randint(65,90))
else:
temp = str(random.randint(0,9))
code+=temp
print(code)
input_user = input("请输入验证码:")
if input_user == code:
print("。。。。。。。。。欢迎。。。。。。。")
break
else:
print("您输入的验证码不正确。")
原文:http://www.cnblogs.com/jcplee/p/7712606.html