Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python程序在生成用于索引列表的随机数时挂起_Python_Python 3.x - Fatal编程技术网

Python程序在生成用于索引列表的随机数时挂起

Python程序在生成用于索引列表的随机数时挂起,python,python-3.x,Python,Python 3.x,这个问题现在几乎没用了。请忽略它。我为自己感到非常尴尬/后悔浪费了其他成员的时间来指出我自己的粗心 系统:64位Windows 10机器 Python安装:win32上的Python 3.7.0(v3.7.0:1bf9cc5093,2018年6月27日,04:06:47)[MSC v.1914 32位(英特尔)] 编辑器:来自sublime text 3的原始代码,现在在VS代码上编辑[最新稳定版本] 我是python新手,一直在使用cmd运行密码管理器程序 我使用了一个我以前做的函数来生成随机

这个问题现在几乎没用了。请忽略它。我为自己感到非常尴尬/后悔浪费了其他成员的时间来指出我自己的粗心

系统
64位Windows 10机器

Python安装
win32上的Python 3.7.0(v3.7.0:1bf9cc5093,2018年6月27日,04:06:47)[MSC v.1914 32位(英特尔)]

编辑器:来自sublime text 3的原始代码,现在在VS代码上编辑[最新稳定版本]

我是python新手,一直在使用cmd运行密码管理器程序

我使用了一个我以前做的函数来生成随机字符串[密码],由主脚本存储在文件中。它从另一个py文件导入到主脚本中。 代码挂起在while count中下面的第二行代码上!=长度循环[来自导入脚本的代码] 这一行代码以前也用过 抱歉,示例代码太长了

长度:由用户输入定义的变量;已转换为int以供以后使用

计数:在此循环之前,变量设置为0

字符类型:一些字符列表[大写、小写、符号、数字]

incl_upp = False
incl_low = False
incl_int = False
incl_sym = False
checklist = []
char_types = []
password = []
length = input('# input length of password in integers | ')
if input('# include upper case alpha? (y/n) | ') == 'y':
    incl_upp = True
    print("# password now includes upper case alpha")
if input('# include lower case alpha? (y/n) | ') == 'y':
    incl_low = True
    print("# password now includes lower case alpha")
if input('# include integers? (y/n) | ') == 'y':
    incl_int = True
    print("# password now includes integers")
if input('# include special characters? (y/n) | ') == 'y':
    print("# password now includes special characters")
    incl_sym = True
if incl_upp == True:
    char_types.append(UPPER_CASE)
    checklist.append(UPPER_CASE)
if incl_low == True:
    char_types.append(LOWER_CASE)
    checklist.append(LOWER_CASE)
if incl_int == True:
    char_types.append(NUMBERS)
    checklist.append(NUMBERS)
if incl_sym == True:
    char_types.append(SYMBOLS)
    checklist.append(SYMBOLS)
while True:
    count = 0
    while count != length:
        case = char_types[random.randint(0,int(len(char_types)-1))]
        char = case[random.randint(0,int(len(case)-1))]
        password.append(str(char))
        count = count + 1
    # for every char in password, for every type in list, for every character in type, check if that is in password
    for i in range(len(password)):
        for x in range(len(checklist)):
            for y in range(len(checklist[x])):
                if checklist[x[y]] in password[i]:
                    checklist[x] = True
    for i in range(len(checklist)):
        if checklist[i] != True or checklist[i] != False:
            checklist[i] = False
    if all(checklist):
        random.shuffle(password) # added security?
        password = "".join(password)
        return password
我检查了变量、数据类型和可能的语法错误,但没有发现任何可疑之处

如果有人能提供一些关于这个问题是如何产生的想法,我们将不胜感激。我不经常在这里发问,所以如果这个问题看起来不完整,我道歉


感谢您的帮助。

阅读用户输入后,您必须将
长度
转换为整数。否则,将整数与字符串进行比较,而字符串永远不会相等。因此你进入无限循环

length = int(input('# input length of password in integers | '))

什么是可变长度?请提供完整的缩进并修复缩进。什么是
长度
?它不会在代码中的任何其他地方引用。可能的问题是
长度
不是您所期望的。很抱歉,问题不完整,希望进行此编辑helps@albert创建MCVE有点困难,问题中的代码依赖于一点设置,这将很难通过。注意:我提交的代码是在一个循环中,该循环检查所有字符类型是否都在结果列表中,以便稍后重新连接[password.join(“”)]。但我的问题是程序只是挂在问题代码的第二行。另外,缩进在VS代码中显示为有效,我不明白你发现它有什么错误。哦!谢谢非常抱歉,这纯粹是我自己的疏忽。非常抱歉浪费了你的时间。非常感谢你的帮助。这个问题不会很好地为他人服务,将被删除。