educative.io

Educative

Why is this showing no next attribute?

class Node:

def __init__(self,key):

    self.key = key

    self.next = None

class LinkedList:

def __init__(self):

    self.head = None



def append(self,data):

   

    if self.head == None:

        self.head = Node(data)

    else:

        cur = self.head

        while cur.next != NULL:

            cur = cur.next

        cur.next = Node(data)

def printval(self):

    cur = self.head

    while cur != NULL:

        print(cur.key)

        cur = cur.next

ll = LinkedList()

ll.append(4)

ll.append(3)

ll.printval()


Type your question above this line.

Course: https://www.educative.io/collection/10370001/5474278013140992
Lesson: https://www.educative.io/collection/page/10370001/5474278013140992/6585350854017024

Hi @Mohammad_Alim,
As I tested the code, it worked just fine, and it is also showing the next attribute. Try to run it on the educative platform.
Happy learning.
Thank you.