title: Python error: global name Xis not defined
body: <p>I've attached my Python Code below for a program our teacher as gave us in school. I keep on encountering an error "global name 'passwordValid' is not defined" and cannot find any way to solve this. This error occurs in the <code>Password.append(passwordValid)</code> line.   </p>
  
  <pre><code>global firstName
  global lastName
  global cateGory
  global passwordValid
  global passwordNew
  firstName = ""
  lastName = ""
  cateGory = ""
  
  
  def newMember():
  #Recieve user input to assign values to variables
      firstName = str(input("Please enter your first name."))
      lastName = str(input("Please enter your last name."))
  
      #Validation to reject unspecifyed category input
      cateGoryValid = False
      while cateGoryValid == False:
          cateGory = str(input("PLease enter your category from the following:    (Junior,Adult,Senior)"))
          cateGory = cateGory.lower()
          cateGory = cateGory.capitalize()
          if cateGory == "Junior" or cateGory == "Adult" or cateGory == "Senior":
              cateGoryValid = True
          else:
              cateGory = str(input("PLease enter your category from the following: (Junior,Adult,Senior)"))
  
  def passwordValidation():
      #initalising global variables
      #Creating Variables
      Valid = False
      firstCharacter =""
      firstValue = 0
      lastCharacter =""
      lastValue = 0
      passwordNew = ""
      passwordValid = []
  
      #Create conditional loop to validate the password
      while Valid == False:
          passwordNew = str(input("Please enter a new password"))
          #Assigns both the first and last values of the password as variables
          firstCharacter = passwordNew[0]
          lastCharacter = passwordNew[-1]
          #Assigns both values as ASCII characters
          firstValue = ord(firstCharacter)
          lastValue = ord(lastCharacter)
          #Ensures password is within boundaries using ASCII characters
          if firstValue &gt;= 65 and firstValue and lastValue &gt;= 35 and lastValue &lt;=37:
              passwordValid = passwordNew
              Valid = True
  
      return passwordValid
  
  def valuesAppend():
      return passwordValid
      global Forname
      global Surname
      global Category
      global Password
  
      Forename = [""]
      Surname = [""]
      Category  =[""]
      Password = [""]
      Position = 0
      Members = ["","","",""] * 11
  
      #Reading the text file
      file = open("members.txt","rt")
  
      #Create loop to assign all fields to a record
      for line in file:
      fields = line.split(",")
      Members[Position] = [fields[0],fields[1],fields[2],fields[3]]
      #Appending the fields into a global variable
      Forename.append(fields[0])
      Surname.append(fields[1])
      Category.append(fields[2])
  
      Position = Position + 1
  
  #Assigning new variables into the record
  Forename.append(firstName)
  Surname.append(lastName)
  Category.append(cateGory)
  Password.append(passwordValid)
  
  file.close
  
  def categoryInfo():
      totalMembers = 0
      totalMembers = len(Forename)
  
      for counter in range(len(Forename)):
          print(Forename[counter], Surname[counter],Category[counter])
          print("There are:",Category.count("Junior"),"Junior members.")
          print("There are:",Category.count("Adult"),"Adult members.")
          print("There are:",Category.count("Senior"),"Senior members.")
          print("The current total is:",totalMembers,"members.")
  
  def main():
      newMember()
      passwordValidation
      valuesAppend()
      categoryInfo()
  
  main()
  </code></pre>