实现一个简单的验证码生成器
#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = "loki" # Usage: 验证码生成 import random def verification_code(digit): verify_code = "" for count in range(0, digit): int_num = random.randint(0, 9) lower_case = chr(random.randint(97, 122)) upper_case = chr(random.randint(65, 90)) compose = random.choice([int_num, lower_case, upper_case]) verify_code += str(compose) return verify_code print(verification_code(5)) # 5位数的验证码 print(verification_code(10)) # 10位数的验证码