I did the exact same thing as the solution but it gives me an error?

https://www.codecademy.com/courses/linear-data-structures/lessons/learn-queues-python/exercises/queues-python-enqueue?action=resume_content_item

Hello,

this screenshot is taken just after taking the solution to this exercise. As you can see in the line 19 I was reported an error although I did the same thing as the solution, can you please explain me why is it?

Thank you.

Hi @ai-2090

If I understand your post correctly, the error in the console (right-hand pane) came from your code but the code in the editor (middle pane) is the Codecademy provided solution?

We aren’t going to be able to tell you why you got the AttributeError you’re asking about unless we can see the entirety of your code.

:slight_smile:

Hi,

yeah, my code is on the right and the solution is in the middle. Unfortunately, I forgot to save my code before taking the solution so I guess we will never know. -_-

You could always reset the exercise and make another attempt? Otherwise, how do you know you’ve learnt where you went wrong and can correct it? :slight_smile:

2 Likes

You’re right bro, I should do that. : )

1 Like

That error says something about what the situation was, enough to be able to tell that your queue was in an invalid state.

If you intentionally put the solution’s queue in that same invalid state you’ll get the same outcome. The problem is with whatever code put it into that state.

That if-statement runs different code based on the state of the queue. That particular clause of your if-statement therefore has some assumptions about the state. Your error message shows which of those assumptions wasn’t the case. It’s a good assumption, it was supposed to be that way. But it wasn’t. And that says something about what code is responsible (the last piece of code that set this state)

1 Like

I’ve got the same issue, except it’s for Task 3 in this Exercise.
As far as I can tell, my code is the same as the Solution, yet for some reason the compiler(?) doesn’t like it. Initially I thought: “Maybe the indenting of the outer If Statement’s “else” part isn’t correct”. I checked that, and it looks fine to me.

Can someone help me, please?

(The link to this Exercise is below, along with a screenshot of the code highlighted).

https://www.codecademy.com/paths/computer-science/tracks/linear-data-structures/modules/cspath-queues/lessons/learn-queues-python/exercises/queues-python-enqueue

I would try putting the ‘self.tail’ part in parenthesis, as follows (without the quotation marks, of course):
“(self.tail).set_next_node(item_to_add)”.
(On my end, the code runs fine with or without the parenthesis enclosing the ‘self.tail’ instance variable.)

If that doesn’t work, one other thing that I’d do is check to see if something was accidentally deleted from the “set_next_node()” method in ‘node.py’. (Its tab is next to ‘script.py’ at the top of the code editor.)

If none of these things work, then I don’t know what else to try…