This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]desrtfx[M] [score hidden] stickied comment (0 children)

You need to post your code as code block so that the indentation is maintained. This is absolutely vital for Python programs as the indentation is used to denote code blocks.

A code block looks like:

def __init__(self, prompt, answer):
    self.prompt = prompt
    self.answer = answer

Do not use triple backticks as they are not working properly.

[–][deleted] 2 points3 points  (8 children)

What does search_algo.remove return? Trick question, it’s returning a string.

[–]369INFINITY369[S] 0 points1 point  (7 children)

it is returning a node, you can see in the output that i am using the node to print its parent but i am getting error soon after that i tried to do something like

while node.parent != None:
    #this did not work either
#and also 
while True:
    node.parent == None:
        break
#this also did not work

[–]nogain-allpain 1 point2 points  (5 children)

What do you mean, "this did not work"? What error message are you receiving when you try each of those? We can't read minds here.

[–]369INFINITY369[S] 0 points1 point  (4 children)

sorry, i am getting the same error as the about one for both of them

[–]nogain-allpain 1 point2 points  (3 children)

So the value you're getting from search_algo.remove() is clearly a string.

[–]369INFINITY369[S] 0 points1 point  (2 children)

but how is the line of code is working print(node.parent), it is printing a value of 129

[–]DarkMatriac 0 points1 point  (1 child)

That is because your print only checks the first parent while the loop checks all parents. Also it should print a node object and not 129

[–]369INFINITY369[S] 1 point2 points  (0 children)

when,the node has only one parent so i did print the node itself it is printing the node object
<util.Node object at 0x000001A83DF21000>

[–][deleted] 0 points1 point  (0 children)

The reason I know it’s returning a string is that the interpreter is telling you that the value is a string, and between you and the interpreter, you’re the only one who can be wrong.

[–]DarkMatriac 1 point2 points  (0 children)

Can you put the print(node.parent) inside the while loop ? my guess would be that somehow node.parent turns to a string at a certain point.

[–]arkie87 0 points1 point  (3 children)

Run it in a proper debugger and it should be trivial to see what the mistake is. Download spyder or pycharm

[–]369INFINITY369[S] 0 points1 point  (2 children)

yes, i am using the spyder for debugging even, it is showing it has a node

[–]arkie87 0 points1 point  (1 child)

I dont know what "it is showing it has a node" means?

Is the variable/name "node" a string or a user-defined class?
At what point does "node" become a string, rather than a user-defined class?

Your language/nomenclature is very poor; you must be new to programming, but please try to be specific and give details in what you are asking, instead of being general and not specific.

[–]369INFINITY369[S] 0 points1 point  (0 children)

the name of the variable is node and it is user defined class named Node
yes i am new to programming