Build a Linked List - Step 18

Tell us what’s happening:

I have implemented the remove method in my LinkedList class with a proper while loop inside it. However, the auto-grader keeps saying that I need a while loop inside the remove method, even though it is clearly present. I believe this may be an indentation or formatting issue with how the platform is detecting my code, not a logic error. Please help me identify what the checker expects.

Your code so far

class LinkedList:
    def remove(self, element):
        previous_node = None
        current_node = self.head
while current_node is not None and current_node.element != element:
            previous_node = current_node
            current_node = current_node.next


    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


# User Editable Region

def remove(self, element):
    previous_node = None
    current_node = self.head
    while current_node is not None and current_node.element != element:
        previous_node = current_node
        current_node = current_node.next



# User Editable Region


        # If not found, just return
        if current_node is None:
            return

        # If the element is at the head
        if previous_node is None:
            self.head = current_node.next
        else:
            previous_node.next = current_node.next

        self.length -= 1


# Quick test
my_list = LinkedList()
my_list.add(1)
my_list.add(2)
my_list.add(3)
print("Before removal:", my_list.length)  # 3

my_list.remove(2)
print("After removal:", my_list.length)   # 2

Your browser information:

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

Challenge Information:

Build a Linked List - Step 18

Inside the while loop, assign current_node to previous_node.

This is the last part of the instructions.