2016-12-15 85 views
-4

我正在为学校制作一个密码项目,我陷入了一个问题。这里是心不是正常的代码:密码python项目编号

def passwordStrength(password): 
    if password.islower(): 
     print("Your password is weak as it only contains lower case letters") 
    elif password.isupper(): 
     print("Your password is weak as it only contains capital letters") 
    elif password.isnumeric(): 
     print("Your password is weak as it only contains numbers") 
    elif password.islower and password.isupper: 
     print("Your password is medium as it contains no numbers") 
    elif password.islower and password.isnumeric: 
     print("Your password is medium as it contains no uppercases") 
    elif password.isupper and password.isnumeric: 
     print("Your password is medium as it contains no lowercases") 
    elif password.islower and password.isupper and password.isnumeric: 
     print("Your password is strong") 

,但如果我的密码,如“asasASAS1212”键入它说,它不包含数字

+0

'islower'是一个函数,而不是一个属性(等)。 – Sayse

+0

你不叫'islower'和其他人 –

+2

此外,你的同学建议的重复[question](http://stackoverflow.com/q/41117733/1324033)可能会进一步帮助 – Sayse

回答

3

与您的代码的第一个问题是,你是不是要求方法本身。实质上,在每个引用islower,isupper和isnumeric之后,您需要放置括号(即())。

但是,更深层次的问题在于您使用这些方法的意图。函数islower,isupper,isnumeric在语义上不是在语义上分别表示“此字符串具有小写字母字符”,“此字符串具有大写字母字符”和“此字符串具有数字字符”。这些函数检查整个字符串是否由独占这样的字符组成。

因此,如果字符串中有单个数字(例如“asd123”),则islower方法返回false,因为该字符串中的字符不是小写字母。

该问题的解决方案并非非常有效,它将逐个检查字符串中的每个字符。

+0

非常感谢你:) – Cole