1 def check_code(): 2 import random 3 checkcode = ‘‘ 4 for i in range(4): 5 current = random.randrange(0, 4) 6 if current != i: 7 temp = chr(random.randint(65, 90)) 8 else: 9 temp = random.randint(0, 9) 10 checkcode += str(temp) 11 return checkcode 12 while True: 13 code = check_code() 14 print(code) 15 v=code.upper() 16 v2=input("请输入验证码:") 17 v3=v2.upper() 18 if v3==v: 19 print("验证成功") 20 break 21 else: 22 print("验证失败")
原文:https://www.cnblogs.com/rxybk/p/12335911.html