0

The code that I have so far is:

password = input("Please enter a password: ")
letter = len(password)
if letters <= 5:
print ("WEAK")
elif

I know the answer is probably really obvious but I just can't see it - what i need it to be able to see whether the letters are capitals. There is other stuff that I need aswell but I'm working through it one step at a time. Please help?

  • `if 'A' <= c <= 'Z'` where `c` is the character you're checking – m_callens Feb 07 '17 at 19:12
  • 2
    Possible duplicate of [how can i check if a letter in a string is capitalized using python?](http://stackoverflow.com/questions/4697535/how-can-i-check-if-a-letter-in-a-string-is-capitalized-using-python) – Darrick Herwehe Feb 07 '17 at 19:21
  • Do you want to know whether any, or whether all characters in the string are capitals? In either case, how should non-alpha characters and characters from scripts without upper/lower distinction be treated? – das-g Feb 07 '17 at 20:15

1 Answers1

3

String has isupper function:

Use it as follow:

 >>> 'e'.isupper()
 False
 >>> 'E'.isupper()
 True
 >>> 'Ennn'.isupper()
 False
 >>> 'EEE'.isupper()
 >>> 'eee'.isupper()
 False
 >>> 'EEEEe'.isupper()
 False

If you want to check if at lest one char is upper, you can use any

 >>> any([x.isupper() for x in list('eeeeE')])
 True
 >>> any([x.isupper() for x in list('eeee')])
 False
 >>> any([x.isupper() for x in list('EEEE')])
 True

Docs:

https://docs.python.org/2/library/stdtypes.html#str.isupper https://docs.python.org/2/library/functions.html#any

Andres
  • 4,323
  • 7
  • 39
  • 53