The code generation system generates enterprise security code with the data analysis

A Code

# 生成含数据分析功能防伪编码函数,参数schoice设置输出的文件名称
def scode4(schoice):
    intype = inputbox("\033[1;32m     请输入数据分析编号(3位字母):\33[0m", 2, 3)
    # 验证输入是否是三个字母,所以要判断输入是否是字母和输入长度是否为3
    while not str.isalpha(intype) or len(intype) != 3:
        intype = inputbox("\033[1;32m     请输入数据分析编号(3位字母):\33[0m", 2, 3)
    incount = inputbox("\033[1;32m     请输入要生成的带数据分析功能的验证码数量:\33[0m", 1, 0)  #
    # 验证输入是否是大于零的整数,判断输入转换为整数值时是否大于零
    while int(incount) == 0:  # 如果转换为整数时为零,则要求重新输入
        incount = inputbox("\033[1;32m     请输入要生成的带数据分析功能的验证码数量:\33[0m", 1, 0)  #
    ffcode(incount, intype, "", schoice)  # 调用 ffcode函数生成注册信息


# 生成含数据分析功能防伪编码函数,参数scount为要生成的防伪码数量,typestr为数据分析字符
# 参数ismessage在输出完成时是否显示提示信息,为“no”不显示,为其他值显示;参数schoice设置输出的文件名称
def ffcode(scount, typestr, ismessage, schoice):
    randstr.clear()  # 清空保存批量注册码信息的变量randstr
    # 按数量生成含数据分析功能注册码
    for j in range(int(scount)):
        strpro = typestr[0].upper()  # 取得三个字母中的第一个字母,并转为大写,区域分析码
        strtype = typestr[1].upper()  # 取得三个字母中的第二个字母,并转为大写,颜色分析码
        strclass = typestr[2].upper()  # 取得三个字母中的第三个字母,并转为大写,版本分析码
        randfir = random.sample(number, 3)  # 随机抽取防伪码中的三个位置,不分先后
        randsec = sorted(randfir)  # 对抽取的位置进行排序并存储给randsec变量,以便按顺序排列三个字母的位置
        letterone = ""  # 清空存储单条防伪码的变量letterone
        for i in range(9):  # 生成9位的数字防伪码
            letterone = letterone + random.choice(number)
        # 将三个字母按randsec变量中存储的位置值添加到数字防伪码中,并放到sim变量中
        sim = str(letterone[0:int(randsec[0])]) + strpro + str(
            letterone[int(randsec[0]):int(randsec[1])]) + strtype + str(
            letterone[int(randsec[1]):int(randsec[2])]) + strclass + str(letterone[int(randsec[2]):9]) + "\n"
        randstr.append(sim)  # 将组合生成的新防伪码添加到randstr变量
    # 调用wfile()函数,实现生成的防伪码屏幕输出和文件输出
    wfile(randstr, typestr + "scode" + str(schoice) + ".txt", ismessage, "生成含数据分析防伪码共计:", "codepath")

Two runs

Three instructions

random.sample usage, please refer to

https://www.cnblogs.com/fuqia/p/9055521.html

Guess you like

Origin blog.csdn.net/chengqiuming/article/details/93784435