title: AttributeError: 'NoneType' object has no attribute 'name'？
body: <p>I have a question that I cannot solve. This is my code:</p>
  
  <pre><code>class Person:
    def __init__(self, name):
      self.name = name
      self.next = None
  
  class PeopleChain:
    def __init__(self, names):
      if names == []:
          self.leader = None
      else:
        self.leader = Person(names[0])
        current_person = self.leader
        for name in names[1:]:
          current_person.next = Person(name)
          current_person = current_person.next
    def get_nth(self, n):
      """Return the name of the n-th person in the chain.
      &gt;&gt;&gt; chain = PeopleChain(['a', 'b', 'c'])
      &gt;&gt;&gt; chain.get_nth(1)
      'a'
      """
      current_person = self.leader
      for i in range(1, n):
        if i &lt; n:
          current_person = current_person.next
      return current_person.name
  </code></pre>
  
  <p>When I use <code>chain.get_nth(4)</code>, for example, it shows that: </p>
  
  <blockquote>
    <p><code>AttributeError: 'NoneType' object has no attribute 'name'</code>.</p>
  </blockquote>
  
  <p>Here is my code after I changed it:</p>
  
  <pre><code>def get_nth(self, n):
      current_person = self.leader
      for i in range(1, n):
          if i &lt; n:
              current_person = current_person.next
              if current_person is None:
                  raise SomeError #user-defined error
      return current_person.name
  </code></pre>
  
  <p>But it still doesn't work. Why does it not work and how can I fix it? Thank you very much.</p>