【问题标题】:Why isn't my password checker working?为什么我的密码检查器不起作用?
【发布时间】:2016-09-17 13:01:08
【问题描述】:

在我开始“这个字符串中的这个”位之前,它似乎工作正常。

#This is the introduction to the code
import time
MinPass = 6
MaxPass = 12
Uppercase = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
Lowercase = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
Symbols = ["!", "£", "$", "%", "^", "&", "*", "(", ")", "_", "-", "+", "=", ":", ";", "@", "'", "#", "~", "<", ">", "?", "/", "|", "¬", "`"]
print ("Hello, user, welcome to the SSPC program, or the Safe and Secure Password Creater.")

print ("Please type your name")
NAME = input()
print ("Great. For a secure password, do not use your name,", NAME, "!")
time.sleep(2)
print ("Now, lets try with a password. Please enter one here")
EnteredPassword = input("Password: ")
while len(EnteredPassword) < MinPass:
    print ("That password is too small. Please try again")
    EnteredPassword = input("Password: ")
while len(EnteredPassword) > MaxPass:
    print ("That password is too long, please try again")
    EnteredPassword = input("Password: ")
print ("Ok, that password is great!")

if EnteredPassword not in Uppercase:
    continue
    if EnteredPassword not in Symbols:
        print ("Your password is weak")
        continue
elif EnteredPassword in Uppercase:
    continue
    if EnteredPassword in Lowercase:
        continue
    elif EnteredPassword not in Lowercase:
        continue
        if EnteredPassword in Symbols:
            print ("Your password is medium")
        elif EnteredPassword not in Symbols:
            print ("Your password is weak")
elif EnteredPassword in Lowercase:
    continue
    if EnteredPassword in Uppercase:
        continue
        if EnteredPassword in Symbols:
            print ("Your password is strong")
elif EnteredPassword not in Lowercase:
    continue
    if EnteredPassword in Symbols:
        print ("Your password is medium")
    elif EnteredPassword not in Symbols:
        print ("Your password is weak")   

出现的错误信息: 继续循环不正确。 怎么了?在“继续”部分之前它的措辞很好,我不知道出了什么问题...... 如果有任何帮助,我将不胜感激......

【问题讨论】:

  • 在 Python 中,缩进是语言语法的一部分。问题中的缩进是否 100% 与您的代码一样?
  • 您应该尝试包含minimal reproducible example 而不是整个程序。这将帮助您自己隔离问题,如果您不能,则可以节省其他人的时间,因为他们不必阅读整个内容。
  • continue 是一个立即导致循环语句(forwhile)进入下一个迭代的语句。您在没有循环的if 语句中使用continue。您可能还想重新检查您的代码。我很确定,例如EnteredPassword not in Uppercase 没有达到你的预期。
  • 看看regex。顺便说一句,更简单的方法。
  • import string; list(string.ascii_lowercase)list(string.ascii_uppercase) #=> 字母作为列表;还有list(string.punctuation) #=> 符号

标签: python while-loop indentation


【解决方案1】:

我认为问题出在这几行代码

if EnteredPassword not in Uppercase:
    ...
elif EnteredPassword in Uppercase:
    ...

等等 您的 UPPERCASE 变量是一个字符列表,而 EnteredPassword 是一个字符串 在这种情况下,“in”将无法完成您在此处尝试执行的操作。

其次,“继续”并没有像您预期的那样在这里工作!

刚刚看到有人已经对此发表了评论。 重复道歉!

【讨论】:

    猜你喜欢
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 2013-06-15
    相关资源
    最近更新 更多