title: Python How to prompt user to input a reference pointing to the first node of the linked list？
body: <p>I'm working on a singly linked list problem. It is about writing a function to implement a recursive algorithm which counts the number of nodes in a singly linked list.</p>
  
  <p>I'm stuck because I'm required to prompt users to input a reference pointing to the first node of the linked list.</p>
  
  <p>But up to now I'm only able to write a program which users should input elements manually and finally count the node, not through a reference, and count the nodes of the linked list which the reference is pointing to.</p>
  
  <p>Can anyone help me?</p>
  
  <pre><code>class Node:
  
      def __init__(self, data):
          self.data = data
          self.next = None
  
  
  class LinkedList:
  
      def __init__(self):
          self.head = Node(None)
  
      def add(self, item):
          temp = Node(item)
          temp.next = self.head
          self.head = temp
  
      def countNodes(self, node):
          if not node: 
              return 0
          else:
              return 1 + self.countNodes(node.next)
  
      def getCount(self):
         return self.countNodes(self.head)
  
  
  if __name__=='__main__':
      new = LinkedList()
      new.add(1)
      new.add(3)
      new.add(1)
      new.add(2)
      new.add(3)
      new.add(1)
      new.add(2)
  
      print ('Count of nodes is :',new.getCount())
  </code></pre>
  
  <p>To make it clearer, it is not necessary for the users to manually create a linked list like this. The user will input a variable, which is a reference pointing to the first node of a linked list, to my function.</p>