mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-02 07:01:28 -04:00
fix(curriculum): acknowledge tracebacks in binary search tree (#54789)
Co-authored-by: Ilenia <26656284+ilenia-magoni@users.noreply.github.com>
This commit is contained in:
@@ -11,12 +11,14 @@ Note that, your search returns something like `80: <__main__.TreeNode object at
|
||||
|
||||
To change that to print a useful value, define another method named `__str__` in the `TreeNode` class. It takes a single argument `self`.
|
||||
|
||||
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.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should define a method `__str__` that takes a single argument `self`. Remember to use `pass`.
|
||||
|
||||
```js
|
||||
assert.match(code, /def\s+__str__\(\s*self\s*\)/);
|
||||
assert.match(code, /^(\s+)def\s+__init__.+?^\1def\s+__str__\(\s*self\s*\)\s*:\s*\n^\1\1pass/ms)
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ dashedName: step-31
|
||||
|
||||
In the body of the `__str__` method, delete `pass` and return the result of calling the `str()` function with `self.key` as the argument. This is the attribute of the current node object that stores the value associated with the node.
|
||||
|
||||
After returning the result, you should see the exception disappear from the console and the output should now display the value of the `key` associated with the node.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should remove the `pass` keyword from the `__str__` method.
|
||||
|
||||
Reference in New Issue
Block a user