Help with a seemingly simple issue

I have started my lesson 29 for the Comp Sci Learn Tree Traversal by Building a Binary Search Tree

My code is as follows;

class TreeNode:

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


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)
    search_result = bst.search(80)
print('Search for 80:', search_result)

The error raised is " You should print the result of calling bst.search(80) and your print statement should have the first argument as `‘Search for 80:’ "

Double check your indentation there. :3

1 Like

Welcome to the forum @robby.grassman

The instructions did not ask you to declare a new variable.

You should print the result of calling bst.search(80) and your print statement should have the first argument as ‘Search for 80:’.

Happy coding

1 Like

You guys got it right! Thank you so much.

1 Like

You were right, Indentation is my biggest issue so far lol

1 Like

Note, it’s best to use the Ask for Help button