Question: Python I have the error Test Failed: Text.head is not a function. I want to be able to have a member function that can call

Python
I have the error
Test Failed: Text.head is not a function.
I want to be able to have a member function that can call the attributes head and tail of the Text class in the format of
Text.head
Text.tail
without parentheses or changing the names and spelling of the attributes
class Node:
def __init__(self, char=None):
if not isinstance(char, str) or len(char)!=1:
raise ValueError("Node must contain a single character string")
self.char = char
self.prev = None
self.next = None
class Text:
def __init__(self, initial_data=None):
self.head = None
self.tail = None
self.length =0
if initial_data:
if isinstance(initial_data, str):
for char in initial_data:
self.append(char)
elif isinstance(initial_data, Text):
current = initial_data.head
while current:
self.append(current.char)
current = current.next
else:
raise TypeError("Initial data must be a string or Text object")
def head():
return self.head
def tail():
return self.tail

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 Programming Questions!