【解決方法】有効なパスワードを検索しています


A website requires the users to input username and password to register. Write a program to check the validity of password input by users (using tuples only) Following are the criteria for checking the password: 1. At least 1 letter between [a-z] 2. At least 1 number between [0-9] 1. At least 1 letter between [A-Z] 3. At least 1 character from [$#@] 4. Minimum length of transaction password: 6 5. Maximum length of transaction password: 12 Your program should accept a sequence of comma separated passwords and will check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma. If none of the password is valid, you should print "invalid"

私が試したこと:

Python
p=list(input())
while len(p)>0:
    ps=[]
    for i in range(len(p)-1):
        if p[i]==",":
            p.remove(p[i])
            break
        else:
            ps.append(p[i])
            p.remove(p[i])
    for k in ps:
        if len(ps)>5 or len(ps)<13:
            if k.isalpha() or k.isdigit() or (k in ["@","#","$"]):
                print(k,end="")
            else:
                break
        else:
            break

解決策 1

Python
if len(ps)>5 or len(ps)<13:

長さが 5 より大きい値 (つまり 6 から無限大)、または 13 より小さい値 (つまり 12 から負の無限大) の場合、その式は成功します。 テストは、式 1 AND 式 2 に対して行う必要があります。

Python
if len(ps)>5 and len(ps)<13:

解決策 2

拡張します リチャードの観察、あなたは実際に使用しています OR どこにでも AND 必須: 入力パスワードはすべての要件を満たす必要がありますが、いずれかが満たされていればコードは問題ありません。

コメント

タイトルとURLをコピーしました