Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help creating a deleting function for my assignment. the deleting is similar to the retrieving functionall it needs to do is delete the

from BST import * from student import * gTotalAges = 0 def AddAges(s): global gTotalAges gTotalAges += int(s. GetAge()) def mclass Node: def __init__(self, item): self.mItem = item self.mL = None self.mR = None class UUC: def _init__(self): self.mRooif current.mk is None and current.mL is None: current = None elif current.mk is not None and current.mL is None: current = cuclass Student: def _init__(self, l, f, s, e, a): self.mLast = 1 self.mFirst = f self.mSSN = s self.mEmail self.mAge = a e def I need help creating a deleting function for my assignment. the deleting is similar to the retrieving functionall it needs to do is delete the content in the file.

from BST import * from student import * gTotalAges 0 def AddAges (s): global gTotalAges gTotalAges += int(s.GetAge()) def main(): global gTotalAges studentList = UUC () ########## Inserting ########## fin = open("InsertNames.txt","r") for line in fin: words = line.split() s Student (words [0], words [1], words [2], words [3], words [4]) ok studentList. Insert(s) if not ok: print("Error inserting", words [1]) fin.close() print("Students inserted:", studentList.Size()) ########## Traversing ########## studentList. Traverse (AddAges) avegTotalAges / studentList.Size() print("The average age is", ave) ########## Deleting ########## fin = open("DeleteNames.txt") for ssn in fin: ssn ssn.strip() found= False for i in range (len (Student)); s2 students [i] if s2.GetSSN() == ssn: found = True students.pop(i) break fin.close() print("Time taken for DeleteNames is:", end-start) ########## Retrieving ########## fin = open("RetrieveNames.txt","r") totalAge = 0 count = 0 for line in fin: ssn line.strip() else: s1 Student ("", "" , ssn, s2 = studentList. Retrieve(s1) if s2 is None: print("Error retrieving student with ssn of", ssn) 111 totalAge + int (s.GetAge()) count += 1 print("Average age of retrieved student is", totalAge / count)

Step by Step Solution

3.47 Rating (163 Votes )

There are 3 Steps involved in it

Step: 1

The contents of a file can be effectively deleted by using th... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Communication Process and Product

Authors: Mary Ellen Guffey

6th Edition

324578679, 9780324578683, 9780324542905, 176721258, 9780324578676, 324542909, 9780176721251, 978-0324542905

More Books

Students also viewed these Mathematics questions

Question

For any S T, 1. int S int T 2.

Answered: 1 week ago

Question

Why should goals be specific and measurable?

Answered: 1 week ago

Question

How is the 6-x-6 rule applied in preparing bulleted points?

Answered: 1 week ago