Question: python please Continuing on from the previous questions, add the get_sum_string_lengths (self) method to the Node class. The get_sum_string_lengths() method returns the sum of the

python please Continuing on from the previous questions, add the get_sum_string_lengths (self)method to the Node class. The get_sum_string_lengths() method returns the sum ofpython please

Continuing on from the previous questions, add the get_sum_string_lengths (self) method to the Node class. The get_sum_string_lengths() method returns the sum of the string lengths in the chain of nodes starting at the node this method is called on. Note: Submit the entire class definition in the answer box below. You can assume that all nodes contain string elements only. For example: Test Result 6 3 node1 = Node('abc') node2 = Node('def') node1.set_next(node2) print(node1.get_sum_string_lengths()) print(node2.get_sum_string_lengths()) node1 = Node('life') node2 = Node('is', nodel) node3 = Node ('long', node2) node4 = Node ('journey', node3) print(node1.get_sum_string_lengths()) print(node4.get_sum_string_lengths()) 4 17 HNMON Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) 1 class Node: 2 3 def _init__(self, data, next=None): self.__data ='data self.__next= next def get_data(self): return self.__data 9 10 def set_data(self, data): 11 self.__data data 12 13 def get_next(self): 14 return self.__next 15 16 def set_next(self, next): 17 self.__next next 18 19 def add_after(self, value): 20 temp = self. --next 21 self.__next = Node(value, temp) 22 def -_str__(self): return str(self.__data) def remove_after(self): temp_node-self.get_next() self.set_next(temp_node.get_next() def get_sum_string_lengths(self): sum1-0 while(self): sum1+=self.__data self=self.__next return sum1 Continuing on from the previous questions, add the __contains__(self, value) method to the Node class. The __contains__() method takes a value as a parameter and checks whether a chain of nodes contains the parameter value. This method returns True if the parameter value is present in the chain of nodes, and returns False otherwise. Note: Submit the entire class definition in the answer box below. For example: Test Result False True True True node1 = Node('hello') node2 = Node( 'world') node3 = Node( 'happy') node4 = Node('coding') node1.set_next(node2) node2.set_next(node) node3. set_next(node4) print("hello" in node4) print("hello" in node1) print("coding" in node4) print("coding" in node1) False False False True node1 = Node (5) node2 = Node ( 10, node1) node3 = Node (30, node2) node4 = Node ( 40, node3) print(1 in node1) print(1 in node4) print(40 in node1) print(40 in node4)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!