numberplate validation problems in python
Question: I am doing a practice assessment for school and me and my friends have been
having problems with this code

    
    
       if len(numberplate)==7:
            if numberplate[0].isalpha:
                if numberplate[1].isalpha:
                    if numberplate[2].isnumeric:
                        if numberplate[3].isnumeric:
                            if numberplate[4].isalpha:
                                if numberplate[5].isalpha:
                                    if numberplate[6].isalpha:
    

What it should do:

  * if the `numberplate` is `GT45HOK` then `print('valid input')`
  * if it is `GT5HYKU` then it should `print('invalid input')`

But because it's 7 letters long it `print('valid input')`


Answer: As you can read in _jonrsharpe_ 's comments, your code doesn't work because
`isalpha` doesn't return the result you want here. `isalpha()` is what you
need, this returns the `boolean` you're after.

_However_ , I would use a [regular
expression](https://developers.google.com/edu/python/regular-expressions)
here. It matches 2 capital alphabetic letters, 2 numbers, and 3 more capital
letters.

    
    
    import re
    
    numberplate = 'GT45HOK'
    r = re.compile('[A-Z]{2}[0-9]{2}[A-Z]{3}')
    if r.match(numberplate):
        print 'valid input'
    else:
        print 'invalid input'
    

