title: Class BST, find value
body: <p>I am having problems with a BST; I wrote a class that represents BSTs but I can't return <code>True</code> or <code>False</code> whether a number is in the BST or not. Any idea why it always returns <code>None</code>? It only gives me the right answer when I ask about the root.</p>
  
  <pre><code>class DrzewoBST:
      def __init__(self, value = None):
          self.val = value
          self.left = None
          self.right = None
  
      def __str__(self):
          return "[%s, %s, %s]" % (self.left, str(self.val), self.right)
  
      def wstawianie(self, wartosc):
          if self is None:
              self = DrzewoBST(wartosc)
          if wartosc &lt; self.val:
              if self.left is None:
                  self.left = DrzewoBST(wartosc)
              else:
                  self.left.wstawianie(wartosc)
          elif wartosc &gt; self.val:
              if self.right is None:
                  self.right = DrzewoBST(wartosc)
              else:
                  self.right.wstawianie(wartosc)
  
      def wyszukiwanie(self, liczba):
          print(self.val)
          if self is None:
              return False
          if int(self.val) == liczba:
              return True
          if liczba &lt; self.val:
              self.left.wyszukiwanie(liczba)
          else:
              self.right.wyszukiwanie(liczba)
  
       t = DrzewoBST(2)
       t.wstawianie(3)
       t.wstawianie(3)
       print(t.wyszukiwanie(3))
  </code></pre>
  
  <p>That works only when I try <code>t.wyszukiwanie(2)</code> (that gives me <code>True</code>) but when I try <code>t.wyszukiwanie(3)</code> I got <code>False</code>; I should get <code>True</code> because 3 is in the BST.</p>