-4

I was making a password project for school and i got stuck on one problem. Here is the code the isnt working properly:

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")

but if i type in a password such as "asasASAS1212" it says it contains no numbers

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
Cole
  • 1

1 Answers1

3

The first issue with your code is that you are not calling the methods themselves. In essence, you need to put brackets (i.e. ()) after each reference to islower, isupper and isnumeric.

A deeper issue lies in the intention behind your usage of those methods, though. Functions islower, isupper, isnumeric do not semantically mean "this string has lowercase alphabetical characters", "this string has uppercase alphabetical characters" and "this string has numerical characters", respectively. Those functions check whether the entire string consist solely of such characters.

So, if there is a single digit in the string(e.g. "asd123"), method islower returns false, because there are characters in that string that are not a lowercase letter.

A solution to that problem, and not a very efficient one, is checking each character in the string individually.

ilim
  • 4,477
  • 7
  • 27
  • 46