【发布时间】:2021-02-19 13:14:02
【问题描述】:
所以我正在尝试制作密码强度检查器,但在尝试检查密码的正确输入长度然后尝试测试运行代码时它显示未定义的名称“pwd”第 12 行。但是我无法找到解决方法这。请帮忙!谢谢。
def pwd_validate(pwd):
# Validate the length of the password
while True:
pwd = input("Please enter your new password, it should be 12 characters long: ")
if len(pwd) == 12:
print("""Thank you for entering a 12 charcter password
Now checking strength of password...""")
break
else:
print("Password must contain only 12 characters please:")
pwd_validate(pwd)
【问题讨论】:
-
不使用
pwd为什么要作为参数?只需将定义更改为def pwd_validate():,然后调用为pwd_validate()。 -
你传递给
pwd_validate的是什么?不能是该函数本身从用户那里获得的密码……
标签: python python-3.x function arguments