title: Data Validation - Postal Code
body: <p>I have been posed the following problem:</p>
  
  <p>Define a function postalValidate(S) which first checks if S represents a postal code which is valid:
  first, delete all spaces;
  the remainder must be of the form L#L#L# where L are letters (in either lower or upper case) and # are numbers.
  If S is not a valid postal code, return the boolean False. If S is valid, return a version of the same postal code in the nice format L#L#L# where each L is capital.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>def postalValidate(S):
  S = S.replace(" ", "")
     for c in range(0, 4, 2):
        if S[c].isalpha() == True:
           x = True
     for c2 in range(1, 5, 2):
        if S[c2].isdigit() == True:
           y = True
     if x == True and y == True:
              return S.upper()
     else:
        return False
  </code></pre>
  
  <p>Problem is, I get this error:</p>
  
  <blockquote>
    <p>UnboundLocalError: local variable 'y' referenced before assignment</p>
  </blockquote>
  
  <p>Help with this would be greatly appreciated.  </p>