Comments (5)
Yea, I answered my own question. I changed the class find
function to:
def find(self, value):
if self.root:
return BST._find(value, self.root)
else:
return False
And got the desired results.
from cmc-csci046.
Great questions!
-
You should always use
super
inside the__init__
function for a subclass, so you're second version is correct. -
You are correct that the function should return
False
instead ofNone
. It returnsNone
because any function that ends without areturn
statement implicitly returnsNone
. You can fix this by adding an else statement after your last if within_find
that returnsFalse
.I thought I had a not in the comments about this, but I just looked and it looks like it got deleted while I was editing my solution code. Sorry about that.
PS. I made some minor edits to your comment for formatting, but overall it was a great example of a well formatted comment.
from cmc-csci046.
Thanks for the reply!
Regarding the 2nd question, I added an else statement
(see below), and it still returns None
with the same Input and Output code as above.
def _find(value, node):
if value > node.value and node.right: #and node right exists
return BST._find(value,node.right)
elif value < node.value and node.left:
return BST._find(value,node.left) #I removed the self. in front of _find
if value == node.value:
return True
else:
return False
This is what my class find
function is:
def find(self, value):
if self.root:
if BST._find(value, self.root):
return True
else:
return False
Do I need to change the return True
to something else in the nested if
statement?
Thanks, Ethan
from cmc-csci046.
I also had a couple questions on homework 10 the BST.py
file if anyone can help!
- I'm getting a
NameError: name 'root' is not defined
when I run what I currently have and am not sure how to adjust it.
class BST(BinaryTree):
'''
FIXME:
BST is currently not a subclass of BinaryTree.
You should make the necessary changes in the class declaration line above
and in the constructor below.
'''
def __init__(self, xs=None):
'''
FIXME:
If xs is a list (i.e. xs is not None),
then each element of xs needs to be inserted into the BST.
'''
super().__init__(root)
- I am having trouble testing my code because it is not even running and I am getting the error below. Is this an issue with how Iām testing this or an issue somewhere in my code and how can I approach this?
The error is referencing the line:
from Trees.BinaryTree import BinaryTree, Node
from cmc-csci046.
-
The
root
variable insuper().__init__(root)
should just beself
. That is, the full command should besuper().__init__()
. -
You should run the
python3
command from the~/trees
folder instead of~/trees/Trees
. Then, you can import theBST.py
file with the commandimport Trees.BST
.
from cmc-csci046.
Related Issues (20)
- saving outputs/geoTwitter20-01-01.zip.lang: not found
- Disk quota full with 50M HOT 3
- MapReduce assignment README content HOT 1
- End of Semester In-Persons HOT 1
- Update Matplotlib, Sort Bar Graph HOT 2
- Unicode Character Hashtags HOT 1
- Class Updates HOT 3
- hw_twitter grade HOT 1
- Another Extra Credit Opportuninty HOT 12
- Yet another extra credit opportunity HOT 6
- Issue with pip3 Install HOT 2
- Issue logging into server
- Wordial Task 1 Command HOT 2
- My worst enemy: Phantom disk quota HOT 2
- questions re: extra credit opportunities from issue #549 & #550 HOT 1
- Caveat Task: Diving into the Hacking Culture
- Missing Failed Cases in Wardial HW
- how to start the typespeed game? HOT 1
- Everything is updated in sakai
- avltree branch connected to bst branch
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cmc-csci046.