Python
This is the requirement of the assignment
Problem (1) Create Node Classes
Node classes have _data and _next as member variables. Values of _data and _next member variables must be readable and changeable through Python properties.
Generates _data and next member variables from the init of the Node class.
It is implemented so that the value of each member variable can be read through @property.
@.Implementation to change the value of each member variable through setter.
And there’s also a template.
class Node(object):
def __init__(self, data=None):
pass
This is the code I wrote.
class Node(object):
def __init__(self, data=None):
self._data = data
self._next = None
@property
def data(self):
return self._data
@property
def next(self):
return self._next
@data.setter
def data(self, new_data):
self._data = new_data
@next.setter
def next(self, new_next):
self._next = new_next
There are member variables, properties, and setters. What’s the problem? In the assignment submission column, it keeps saying “An instance of node class should have _data member variable.”
Please help me.
Create Node Classes with Python
user24844547 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.