Learn Tree Traversal by Building a Binary Search Tree - Step 30

Tell us what’s happening:

I have tried everything and the only answer is that I must have a formatt error but I cant seem to find it and continue: This is the error i get:Traceback (most recent call last):
File “main.py”, line 47, in
File “https://www.freecodecamp.org/js/workers/
1.0.1/python-worker.js”, line 1, in Object.print
File “https://www.freecodecamp.org/js/workers/
1.0.1/python-worker.js”, line 1, in ???
str_returned non-string (type Non

TypeError:
eType)

Your code so far


class TreeNode:

    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None

# User Editable Region
    def __str__(self):
        pass
# User Editable Region
class BinarySearchTree:

    def __init__(self):
        self.root = None

    def _insert(self, node, key):
        if node is None:
            return TreeNode(key)

        if key < node.key:
            node.left = self._insert(node.left, key)
        elif key > node.key:

            node.right = self._insert(node.right, key)
        return node

    def insert(self, key):
        self.root = self._insert(self.root, key)
        
    def _search(self, node, key):
        if node is None or node.key == key:
            return node
        if key < node.key:
            return self._search(node.left, key)
        return self._search(node.right, key)
    
    def search(self, key):
        return self._search(self.root, key)

bst = BinarySearchTree()

nodes = [50, 30, 20, 40, 70, 60, 80]

for node in nodes:
    bst.insert(node)

print('Search for 80:', bst.search(80))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36

Challenge Information:

Learn Tree Traversal by Building a Binary Search Tree - Step 30

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/learn-tree-traversal-by-building-a-binary-search-tree/65c646d4148ae3b2d1cbcac4.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @a.zhang,

The instructions said your code would throw an exception in this step:

After defining __str__ you’ll get an exception in the console because the __str__ method doesn’t return anything yet. You’ll work on the method body in the next step.

Try checking your code to move on…

Happy coding

Hi!
I did this and it does not move on: class TreeNode:

def \__init_\_(self, key):

    self.key = key

    self.left = None

    self.right = None



def \__str_\_(self):

    pass

Your solution works from my end. Please try one of the following steps to move forward.

Click on the “Restart Step” button and force a refresh of your page with CTRL + F5 then try to paste the code in again.

or - Try the step in incognito or private mode.

or - Disable any/all extensions that interface with the freeCodeCamp website (such as Dark Mode, Ad Blockers, or Spellcheckers), and set your browser zoom level to 100%. Both of these factors can cause tests to fail erroneously.

or - Ensure your browser is up-to-date or try a different browser.

I hope one of these will work for you.

Thank you so much, I had to try another browser all the other optionas did not work before.