I need help creating a deleting function for my assignment. the deleting is similar to the retrieving
Fantastic news! We've Found the answer you've been seeking!
Question:
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.
Transcribed Image Text:
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) 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)
Expert Answer:
Answer rating: 100% (QA)
The contents of a file can be effectively deleted by using th... View the full answer
Related Book For
Business Communication Process and Product
ISBN: 978-0324542905
6th Edition
Authors: Mary Ellen Guffey
Posted Date:
Students also viewed these mathematics questions
-
(a) Find each sum. 1 + 2 + 3 + 4 + 5 = ? 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = ? 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = ? (b) Use the formula below for the sum of the first n natural numbers to verify...
-
For any S T, 1. int S int T 2.
-
What is the shear capacity of the RC beam described below considering the steel reinforcement and using the formula: VRsyAw 2fyd cot 8/s The shear reinforcement in the beam is provided by sets of...
-
Refer to E 29 and respond to the following requirements. Data in E 2-9 Prepare the necessary adjusting entries on December 31, 2024, for the Microchip Company for each of the following situations....
-
Predict the product(s) of this elimination reaction. OH acid
-
Superheated steam at 500 kPa, 180C is expanded in a nozzle to pressure of 170 kPa. Assuming the expansion process to be isentropic and in equilibrium determine the exit velocity. Assuming the flow to...
-
The simplified financial statements of SPS Ltd appear below. Additional information 1. Dividends declared and paid were \($26\) 400. 2. During the year equipment was sold for \($10\) 200 cash. The...
-
The following data are for four independent process-costing departments. Inputs are added continuously. Required: Compute the equivalent units of production for each of the preceding departments...
-
Locklear Partners started a new business on July 1, 2021. That same day, Locklear Partners also received $90,000 of cash from issuing common stock and borrowed $80,000 from a friend. On July 1, 2021...
-
6.2. Data has been collected from a chemical reactor. The inlet concentration was the only input variable that changed when the data was collected. The input and output data is given in Table Q6.2....
-
Pull data for the Nareit Equity REIT Share Price Index, the Nareit Mortgage REIT Price Index, and the NCREIF Property Index. Calculate the holding period return over the period from January 2011 to...
-
What is a reasonable domain for the data attribute for a students last name?
-
Can a well-designed database give a business a strategic advantage? How?
-
What is cardinality? Give an example.
-
What attributes would you have in a table to describe a movie?
-
Compare your answer from the above question (grocery store) to that of at least one other student. How were your answers different?
-
Please answer questions where appropriate. Let x be a numpy array with 4 rows and 4 columns: x = numpy.array( [[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12], [13, 14, 15, 16]]) What is the result of...
-
San Carlos Bank and Trust Company uses a credit-scoring system to evaluate most consumer loans that amount to more than $2,500. The key factors used in its scoring system are found at the conclusion...
-
Document for Analysis: Poor Action Request for Internship Your Task. Analyze the poorly written persuasive request. List its weaknesses. If your instructor directs, revise the letter. Add any...
-
How is the 6-x-6 rule applied in preparing bulleted points?
-
Compare primary data and secondary data. Give an original example of each.
-
For the Biot problem in a slab by expanding the sin and cos term and keeping only terms up to \(\lambda^{2}\) the following approximate relation can be obtained for the eigenvalues for small Biot...
-
A hot dog at \(5^{\circ} \mathrm{C}\) is to be cooked by dipping it in boiling water at \(100^{\circ} \mathrm{C}\). Model the hot dog as a long cylinder with a diameter of \(20 \mathrm{~mm}\). Find...
-
A finite cylinder is \(2 \mathrm{~cm}\) in diameter and \(3 \mathrm{~cm}\) long and at a temperature of \(200^{\circ} \mathrm{C}\), and is cooled in air at \(30^{\circ} \mathrm{C}\). The convective...
Study smarter with the SolutionInn App