title: Why is calling function causing a NameError?
body: <p>I am writing this code below but when I am trying to call the function <code>size()</code> it is throwing error</p>
  
  <pre><code>class Node:
      def __init__(self,data):
          self.data=data
          self.left=None
          self.right=None
  
      def insert(self,data):
              if self.data:
                  if data&lt;self.data:
                      if self.left is None:
                          self.left=Node(data)
                      else:
                          self.left.insert(data)
                  else:
                      if self.right is None:
                          self.right=Node(data)
                      else:
                          self.right.insert(data)
              else:
                  self.data=data
  
      def size(node):
          if node is None:
              return 0 
          else:
              return (size(node.left)+ 1 + size(node.right)) 
  
  root=Node(4)
  
  root.insert(5)
  root.insert(3)
  root.insert(8)
  
  print(size(root))
  </code></pre>
  
  <p>The error below is getting thrown:</p>
  
  <pre class="lang-none prettyprint-override"><code>NameError                                 Traceback (most recent call last)
  &lt;ipython-input-7-8c72ba7719dc&gt; in &lt;module&gt;
       41 root.insert(8)
       42 
  ---&gt; 43 print(size(root))
       44 
       45 #root.print()
  
  NameError: name 'size' is not defined
  </code></pre>