FAQs on the exercise Traversing A Binary Search Tree
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
There might be a bug at step 4. This is the method I wrote:
def depth_first_traversal(self):
if self.left:
self.left.depth_first_traversal()
print(f'Depth={self.depth}, Value={self.value}')
if self.right:
self.right.depth_first_traversal()
my solution for the code was not accepted. Also when I manually replaced my code with the offered solution it wouldn’t accept the input. Only by selecting the option to replace my code with the solution the input was accepted and I could continue the lesson.
Same Issue here as well. Wrote the same code and both the Get Unstuck version of the code and the above verion of the code produces the same results. If it is not a bug and there is a reason to use:
def depth_first_traversal(self):
if (self.left is not None):
self.left.depth_first_traversal()
print(f'Depth={self.depth}, Value={self.value}')
if (self.right is not None):
self.right.depth_first_traversal()
Over:
def depth_first_traversal(self):
if self.left:
self.left.depth_first_traversal()
print(f'Depth={self.depth}, Value={self.value}')
if self.right:
self.right.depth_first_traversal()
The reason would definitely be a good addition to the lesson.
I have to assume readability but I also assume the readability of a truthy/falsey statement, would not be an issue for any advanced Python users.
I was having the same issue and came to the Forums to see if others were having the same problem. I also would like to know if there is a practical reason for it or if it is just a bug
def depth_first_traversal(self):
if self.left is not None:
self.left.depth_first_traversal()
print(f'Depth={self.depth}, Value={self.value}')
if self.right is not None:
self.right.depth_first_traversal()
print(f'Depth={self.depth}, Value={self.value}')
I got an error even in this situation
It doesn’t accepts if we’re using
if self.left / if self.right
print in both if statements
It’d only accept if print was after the if self.left condition