Answered step by step
Verified Expert Solution
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
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...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started