0
USR_PWD = raw_input ("Please Input A 10 Digit Password")
if USR_PWD[0] == chr(range(65,90))
    print "True"

Line 2 does not work, I'm attempting to check and see if the input's first character is a capital letter (65 is A and 90 is Z). Not even sure if this is the best way to go about it either. I'm a beginner so I could be making a very easy mistake but, thanks for the help.

2 Answers2

1

You shouldn't need to use chr. Just check the character is between 'A' and 'Z'.

if 'A' <= USR_PWD[0] <= 'Z':
    print "True"

You could also use if USR_PWD[0].isupper(), but that also returns true for lots of characters outside the A-Z range, like Œ.

khelwood
  • 55,782
  • 14
  • 81
  • 108
0

If you want to know the ASCII code of a character you can use ord(). See here.

In this case your code looks like:

USR_PWD = raw_input ("Please Input A 10 Digit Password")
if ord(USR_PWD[0]) in range(65,90):
    print "True"
RcsAkos
  • 1
  • 2
  • 1
    `in range(...)` is a very inefficient way to check if a number falls within a particular range in Python 2. It constructs a list of numbers and iterates through it to find the number you are looking for. – khelwood Apr 24 '18 at 13:08
  • You are completely right. I only suggested usage of `ord()` because I wanted to point out how it could be done with the original code. – RcsAkos Apr 25 '18 at 09:39