Use app×
QUIZARD
QUIZARD
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
6.3k views
in Computer by (49.6k points)
closed by

Consider a file, SPORT.DAT, containing records of the following structure:

[SportName, TeamName, No_Players] 

Write a function, copyData(), that reads contents from the file 

SPORT.DAT and copies the records with Sport name as “Basket Ball” to the file named BASKET.DAT. The function should return the total number of records copied to the file BASKET.DAT.

1 Answer

+1 vote
by (51.9k points)
selected by
 
Best answer
def copyData():

fObj open ("SPORT.DAT", "rb") 

fObj1 open ("BASKET.DAT", "wb") 

cnt=0

try:

   while True:

         data = pickle.load(fobj) 

         print (data)

         if data[0] "Basket Ball": 

             pickle.dump (data, fObj1) 

             cnt+=1

except:

  fObj.close()

  fObjl.close()

return cnt

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...