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 initself charNone:
if not isinstancechar str or lenchar:
raise ValueErrorNode must contain a single character string"
self.char char
self.prev None
self.next None
class Text:
def initself initialdataNone:
self.head None
self.tail None
self.length
if initialdata:
if isinstanceinitialdata, str:
for char in initialdata:
self.appendchar
elif isinstanceinitialdata, Text:
current initialdata.head
while current:
self.appendcurrentchar
current current.next
else:
raise TypeErrorInitial 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
