Build a Linked List - Step 15

Tell us what’s happening:

It says I should print my_list.length but I am it seems like there is a bug and its not allowing me to pass

Your code so far

class LinkedList:
    class Node:
        def __init__(self, element):
            self.element = element
            self.next = None
            
    def __init__(self):
        self.length = 0
        self.head = None

    def is_empty(self):
        return self.length == 0
    
    def add(self, element):
        node = self.Node(element)
        if self.is_empty():
            self.head = node
        else:
            current_node = self.head
            while current_node.next is not None:
                current_node = current_node.next
            current_node.next = node
        self.length += 1

my_list = LinkedList()
print(my_list.is_empty())


# User Editable Region

my_list = LinkedList()
print(my_list.is_empty())

my_list.add(1)
my_list.add(2)

print(my_list.is_empty())
print(my_list.length
)

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36

Challenge Information:

Build a Linked List - Step 15

Hi @ethanyoung9039

You have a double up in the code.

Happy coding

tysm this helped a lot

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.