Password Strength

Medium · rating 1200 · Strings, Implementation

Read a single line containing a password. Print Strong if it is at least 8 characters long and contains at least one lowercase letter, one uppercase letter, and one digit; otherwise print Weak.

Editorial

Approach

Evaluate four independent conditions: length ≥ 8, and the presence of a lowercase letter, an uppercase letter, and a digit. The password is strong only if all four hold.

p = input()
strong = (len(p) >= 8 and
          any(c.islower() for c in p) and
          any(c.isupper() for c in p) and
          any(c.isdigit() for c in p))
print('Strong' if strong else 'Weak')

Complexity

Time: O(n). Space: O(1).

Related problems

Open Password Strength in Code Arena →