Aprenda travessia de árvores criando uma árvore binária de busca - Passo 30

Conte o que está acontecendo:

Hello! The exercise asks me to create __str__(self) using only pass, but running the code produces TypeError: __str__ returned non-string (type NoneType). I also cannot proceed because the platform keeps showing the same instruction. It seems there may be an inconsistency between the exercise instructions and the test.

Seu código até agora


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))

Informações do seu navegador:

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

Informações do desafio:

Aprenda travessia de árvores criando uma árvore binária de busca - Passo 30

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

Welcome to the forum @gaudenciopedro36,

I’ll open a GitHub issue for this bug. Meanwhile, please move on to the next step.

But I’m not sure this bug will be fixed since you are working in a legacy Python curriculum. I suggest you work through the current Python curriculum instead.

Happy coding

add spaces to this empty line or try Safari

there is a weird bug related to regex in Chrome

Hi, thank you very much! Since I have already completed the current Python curriculum, I decided to work through the legacy one as well. I appreciate your help!

Thank you very much, it worked! I really appreciate it.