# courselist_LV.py - class Node: "A class used to represent a...

• 4
• 100% (1) 1 out of 1 people found this document helpful

This preview shows page 1 - 2 out of 4 pages.

class Node:"""A class used to represent a Node in a Doubly Linked List"""def __init__(self, value=None):"""Constructor for the Node class"""self.value = valueself.next = Noneself.prev = Nonedef __str__(self):"""ToString implementation for the Node class"""return str(self.value)# In[36]:class CourseList:"""A class containing a list of items linked through references"""def __init__(self):"""Constructor for the LinkedList class"""self.head = Noneself.last = Noneself.count = 0def __str__(self):"""ToString implementation for the LinkedList class"""result = ""current = self.headwhile current != None:result += str(current.value)result += "\n"current = current.nextreturn resultdef __iter__(self):self.currentIter = self.headreturn selfdef __next__(self):if self.currentIter != None:self.currentIter = self.currentIter.nextif self.currentIter == None:raise StopIteration()return self.currentIterelse:raise StopIteration()def calculate_gpa(self):gpa = 0.0node =self.headif self.size() > 0:compute = 0.0count = 0.0for i in range( self.length() ):str(node.value.credit_hr()), str(node.value.grade())compute += ( node.value.credit_hr() * node.value.grade() )count += node.value.credit_hr()nodePrev = nodenode = node.nextgpa = compute / count

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 4 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
CharlesD.Allison
Tags