Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.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 - Fatal编程技术网

Python新手,我需要做这个循环?我知道它是';它真的很乱

Python新手,我需要做这个循环?我知道它是';它真的很乱,python,Python,我怎样才能做这个循环,如果可能的话,我能把它整理一下吗 l,a,b, = 0, 0, 0 password = str(input("Please enter a strong, 12 character password: ")) for i in password: if password[0] or [1] or [2] or [3] or [4] or [5] or [6] or [7] or [8] or [9] or [10] or [11] or [12].

我怎样才能做这个循环,如果可能的话,我能把它整理一下吗

l,a,b, = 0, 0, 0
password = str(input("Please enter a strong, 12 character password: "))
for i in password:
 if password[0] or [1] or [2] or [3] or [4] or [5] or [6] or [7] or [8] or [9] or [10] or [11] or 
[12].islower():
  l+=1
if password[0] or [1] or [2] or [3] or [4] or [5] or [6] or [7] or [8] or [9] or [10] or [11] or 
[12].isupper():
a+=1
if len(password) == 12:
b+=1
if l>=1 and a>=1 and b>=1:
print("valid password")
else:
print("invalid password")
  • 清洁剂代码:
  • 像“:”这样的非字母字符呢

  • 请注意,您的代码绝对没有达到预期效果<例如,代码>[1]只是一个整数的单个元素列表。因此,您可能会询问
    AttributeError
    (尽管您没有提及)。您如何描述您正在尝试执行的操作,因为不管是什么,此代码都不会执行。您需要执行类似
    any(map(password,lambda x:x.islower())
    的操作。预期的输入标准是什么?包含您选择的字母表的上下字符的12个长数组?如果您要编写密码强度检查器,有更好的方法。这看起来更好,非常感谢!您还必须注意非字母字符。
    l, a, b, = 0, 0, 0
    password = str(input("Please enter a strong, 12 character password: "))
    for i in password:
        if i.islower():
            l += 1
        if i.isupper():
            a += 1
    if len(password) == 12:
        b += 1
    if l >= 1 and a >= 1 and b >= 1:
        print("valid password")
    else:
        print("invalid password")