Computer Science, asked by dhanushvd88, 4 months ago

We want to add a function length() to the class Node that implements user defined lists which will compute the length of a list. An incomplete implementation of length() given below. You have to provide expressions to put in place of XXX, YYY. and ZZZ.

def length(self):

if self.value == None:

return(XXX)

elif
self.next == None:

return(YYY)

else:

return(ZZZ)

Answers

Answered by vishwakarmaharshita8
0

Answer:

XXX : 0 YYY : 1 ZZZ : 1+self.next.length()

Answered by Jasleen0599
0

Python Code

def length(self):

 if self.value == None:

    return(XXX)

 elif self.next == None:

    return(YYY)

 else:

    return(ZZZ)

Output

XXX: 0, YYY: 1, ZZZ: 1 + self.next.length()

  • To access class-specific variables, use the self parameter, which is a reference to the currently running instance of the class.
  • In Python, the self keyword is applied to each instance of a class. One can quickly access all the instances declared within a class, including its methods and attributes, by using the self keyword. __init__ is one of Python's reserved methods. A function constructors what it is known as in object-oriented programming.

#SPJ2

Similar questions