Can not submit my code

I can not submit my code. I click run and it keeps loading for a long time and after that i get “Failed to test your code”
I dont create any infinite loop.

Hello @phandaiduonghcb, welcome to the forums! Could you post a link to the exercise and the code you have written, please?

https://www.codecademy.com/paths/computer-science/tracks/linear-data-structures/modules/cspath-linked-lists/lessons/learn-linked-lists-python/exercises/linked-lists-python-list-iii
And this is the code:

# We'll be using our Node class
class Node:
def __init__(self, value, next_node=None):
self.value = value
self.next_node = next_node

def get_value(self):
return self.value

def get_next_node(self):
return self.next_node

def set_next_node(self, next_node):
self.next_node = next_node

# Our LinkedList class
class LinkedList:
def __init__(self, value=None):
self.head_node = Node(value)

def get_head_node(self):
return self.head_node

def insert_beginning(self, new_value):
new_node = Node(new_value)
new_node.set_next_node(self.head_node)
self.head_node = new_node

def stringify_list(self):
string_list = ""
current_node = self.get_head_node()
while current_node:
if current_node.get_value() != None:
string_list += str(current_node.get_value()) + "\n"
current_node = current_node.get_next_node()
return string_list

# Define your remove_node method below:
def remove_node(self,value_to_remove):
current_node = self.head_node
if self.head_node.value == value_to_remove:
self.head_node = self.head_node.next_node
else:
while current_node!=None:
if current_node.next_node.value == value_to_remove:
current_node.next_node = current_node.next_node.next_node
current_node =None

What immediately jumps out is the lack of indentation. Is that how your code actually looks?

We’ll be using our Node class

class Node:
def init(self, value, next_node=None):
self.value = value
self.next_node = next_node

def get_value(self):
return self.value

def get_next_node(self):
return self.next_node

def set_next_node(self, next_node):
self.next_node = next_node

Our LinkedList class

class LinkedList:
def init(self, value=None):
self.head_node = Node(value)

def get_head_node(self):
return self.head_node

def insert_beginning(self, new_value):
new_node = Node(new_value)
new_node.set_next_node(self.head_node)
self.head_node = new_node

def stringify_list(self):
string_list = “”
current_node = self.get_head_node()
while current_node:
if current_node.get_value() != None:
string_list += str(current_node.get_value()) + “\n”
current_node = current_node.get_next_node()
return string_list

Define your remove_node method below:

def remove_node(self,value_to_remove):
current_node = self.head_node
if self.head_node.value == value_to_remove:
self.head_node = self.head_node.next_node
else:
while current_node!=None:
if current_node.next_node.value == value_to_remove:
current_node.next_node = current_node.next_node.next_node
current_node =None

Sorry, I dont know how it turned out like that.:

We’ll be using our Node class

class Node:
def init(self, value, next_node=None):
self.value = value
self.next_node = next_node

def get_value(self):
return self.value

def get_next_node(self):
return self.next_node

def set_next_node(self, next_node):
self.next_node = next_node

Our LinkedList class

class LinkedList:
def init(self, value=None):
self.head_node = Node(value)

def get_head_node(self):
return self.head_node

def insert_beginning(self, new_value):
new_node = Node(new_value)
new_node.set_next_node(self.head_node)
self.head_node = new_node

def stringify_list(self):
string_list = “”
current_node = self.get_head_node()
while current_node:
if current_node.get_value() != None:
string_list += str(current_node.get_value()) + “\n”
current_node = current_node.get_next_node()
return string_list

Define your remove_node method below:

def remove_node(self,value_to_remove):
current_node = self.head_node
if self.head_node.value == value_to_remove:
self.head_node = self.head_node.next_node
else:
while current_node!=None:
if current_node.next_node.value == value_to_remove:
current_node.next_node = current_node.next_node.next_node
current_node =None

Is the code above OK?

Thank god I got it, sorry for wasting your time

Vào 9:31 Th 6, 12 thg 6 2020 Phan Đại, Dương <19520482@gm.uit.edu.vn> đã viết: