title: Mapping a Boolean function over a list
body: <p>I'm new to programming so this is probably a silly question!</p>
  
  <p>I'm trying to write a function that takes a list of letter grades and returns a Boolean true or false depending on whether it is a passing grade</p>
  
  <pre><code>## Calculate total units passed
  
  def unitPassed(letterGrade):
      if letterGrade == 'N':
          passed = False
      else:
          if letterGrade == 'NCN':
             passed = False
          else:
              if letterGrade == 'WN':
                  passed = False
              else:
                  True
      return passed
  
  unitsPassed = map(unitPassed,courseGradeLetter)
  </code></pre>
  
  <p>I've attempted to do this by creating a function that tests if a grade is a passing grade, and then map this over a list of grade.</p>
  
  <p>The problem is that I get the following error for a list that contains more than one element:</p>
  
  <pre><code>local variable 'passed' referenced before assignment
  </code></pre>
  
  <p>If I try it with a list containing one element I get the correct result.</p>
  
  <p>Any ideas why this is?</p>
  
  <p>Thanks.</p>
  
  <p>--</p>
  
  <p>Thanks everyone, your answers have helped me a lot!</p>