CBSE Class 12 Computer Science File Handling Worksheet Set A

Read and download free pdf of CBSE Class 12 Computer Science File Handling Worksheet Set A. Download printable Computer Science Class 12 Worksheets in pdf format, CBSE Class 12 Computer Science File Handling Worksheet has been prepared as per the latest syllabus and exam pattern issued by CBSE, NCERT and KVS. Also download free pdf Computer Science Class 12 Assignments and practice them daily to get better marks in tests and exams for Class 12. Free chapter wise worksheets with answers have been designed by Class 12 teachers as per latest examination pattern

File Handling Computer Science Worksheet for Class 12

Class 12 Computer Science students should refer to the following printable worksheet in Pdf in Class 12. This test paper with questions and solutions for Class 12 Computer Science will be very useful for tests and exams and help you to score better marks

Class 12 Computer Science File Handling Worksheet Pdf

1. Data File Data files are the files that store and preserve data released to a particular application.
Computers store every file as a collection of 0s and 1s, i.e. in binary form. Therefore, every file is basically just a series of bytes stored.

2. Text File It is a sequence of characters consisting of alphabets, numbers and other special symbols.
It stores information in ASCII characters. In text file, each line of text is terminated with a special character known as EOL (End of Line) or delimiter.

The file extension of text file is .txt.

(i) Opening a File In file handling, the first requirement is opening a file. Once a file is opened, read, write, append, close, etc., can be performed on the file. To open a file, open() method is used in Python.

(ii) Closing a File It is important to close files as soon as you have finished your work with file.
Opened file is closed by calling the close() method of its file objects.

(iii) Writing into Files For writing to a file, we first need to open it in write or append mode. In Python, there are two methods of file objects which are used to write data into a files.

• write() This method takes a string and writes it into the file. This method does not add a newline character (‘\n’) to the end of the string.
Syntax <FileHandle>.write(str1)

• writelines () Whenever, we have to write a sequence of string to a file, we will use writelines() instead of write().
Syntax <FileHandle>.writelines(L)

(iv) Reading from Files After writing information into a file, you must need to read that data at some point. Python provides mainly four types of read methods to read data from file.
• read() This method returns a string containing all characters in a file.
Syntax <FileHandle>.read()

• read([size]) This method specifies how many characters the string should return.
Syntax <FileHandle>.read(n)

• readline() This method will read from a file line by line. For readline(), a line is terminated by ‘\n’ or End of Line (EOL) (i.e. new line character). When end of file is reached, readline() will return an empty string.
Syntax <FileHandle>.readline()

• readlines() This method will return a list of strings, each separated by ‘\n’.
This method reads all rows and retains the newlines character that is at the end of every row.
Syntax <FileHandle>.readlines()

(v) flush() Method This method will force out any unsaved data that exists in a program buffer to the actual file.
Python automatically flushes the files when closing them. But you may want to flush the data before closing any file.
Syntax FileObject.flush()

(vi) Random Access Methods Python provides two methods to perform random access operations in a file. These methods help you to manipulate the position of file pointer and thus you can read and write from desired position in the file.

• tell() Method This method tells you the current position within the file, measured in bytes from the beginning of the file.
Syntax File0bject.tell()

•seek() Method This method can be used to change the current position in a file. This method does not return any value.
Syntax File0bject.seek(offset[,mode])

3. Binary File It is a file that contains information in the same format as it is held in memory. In binary files, no delimiters are used for a line and no translations occur here. They represent the actual content such as image, audio, video, executable files, etc. These files are not human readable. The file extension of binary file is .dat.

(i) Working with Binary File Python object handles the binary files. Python provides a special module-the pickle module which can be used to store any kind of object in file.

(ii) Using dump( ) Method This method is used to write objects to a file. Before use the dump( ) method, you first have to import the pickle module.
Syntax
import pickle
......
......
......
pickle.dump(object_to_pickle,File0bject)

(iii) Using load() Method
This method is used to load data from a binary file.
Syntax
import pickle
......
......
......
object=pickle.load(File0bject)

4. CSV File CSV (Comma Separated Values) format is one of the most simple and common ways to store data in tabular form. Each record consists of one or more fields separated by commas. To represent a CSV file, it must be saved with the .csv file extension.

(i) Working with csv file csv files are used to store a large number of variables or data. They are
incredibly simplified spreadsheets. Each line in a csv file is a data record.

(ii) Read from CSV File Using csv.reader() To read data from csv files, you must use the reader() function to generate a reader object.
This function returns a reader object which is an iterator of lines in the csv file.
Syntax csv.reader(<FileHandle>)

(iii) Write into a CSV File Using csv.writerow() To write an existing file, you must first open the file in one of writing modes (w, a or r+) first. For this, writerow() function is used in Python for csv files.
This function writes items in a sequence (list, tuple or string) separating them by comma character.

 

Direction (Q. Nos. 1-15) Each of the question has four options out of which only one is correct.

Select the correct option as your answer.

1. To read three characters from a file object f, we use ……… .
(a) f.read(3)
(b) f.read()
(c) f.readline()
(d) f.readlines()
Answer : A

2. How do you get the current position within the file?
(a) fp.seek()
(b) fp.tell()
(c) fp.loc()
(d) fp.pos()
Answer : B

3. The files that consists of human readable characters
(a) binary file
(b) text file
(c) Both (a) and (b)
(d) None of these
Answer : B

4. Which function is used to write a list of string in a file?
(a) writeline()
(b) writelines()
(c) writestatement()
(d) writefullline()
Answer : A

5. What will be the output of the following Python code?
myFile = None
for i in range (8):
with open(“data.txt”, “w”) as myFile:
if i > 5:
break
print(myFile.closed)
(a) True
(b) False
(c) None
(d) Error
Answer : A

6. What is the use of seek() method in files?
(a) Sets the file’s current position at the offset
(b) Sets the file’s previous position at the offset
(c) Sets the file’s current position within the file
(d) None of the mentioned
Answer : A

7. What will be the output of the following Python code?
myFile = open(“story.txt”, “wb”)
print(“ Name of the file: ”, myFile.name)
myFile.flush()
myFile.close()
(a) Compilation error
(b) Runtime error
(c) No output
(d) Flushes the file when closing them
Answer : D

Suppose the content of the file ‘‘story.txt’’ is
Education Hub
Learning is the key of success.

8. What is the output of following code?
myfile=open(‘story.txt’,‘r’)
s=myfile.read(10)
print(s)
s1=myfile.read(15)
print(s1)
myfile.close()
(a) Education
Hub Learning is
(b) Education
Hub
Learning is
(c) Education 
Hub
Learning
is
(d) Education Hub
Learning is
Answer : B

9. What is the output of following code?
f=open(‘story.txt’, ‘r’)
s=f.readline()
lcount=len(s)
print(lcount)
f.close( )
(a) 4
(b) 2
(c) 1
(d) 8
Answer : B

10. What is the output of following code?
f=open(‘story.txt’, ‘r’)
str=“ ”
s=0
ts=0
while str:
     str=f.readline()
     ts=ts+len(str)
print(ts)
f.close()
(a) 44
(b) 43
(c) 37
(d) 45
Answer : A

11. What is the output of following code?
def test () :
s=open (“story.txt”, “r”)
f=s.read()
z=f.split( )
count=0
for i in z:
     count=count+1
print(count)
(a) 7
(b) 8
(c) 5
(d) 9
Answer : B

Suppose the content of file ‘‘Para.txt’’ is
Education Hub
Electronic learning
Learning is the key of success

12. What is the output of following code?
def test() :
f=open (“Para.txt”, “r”)
lines=0
l=f.readlines( )
for i in l:
     if i [0] = = ‘E’ :
          lines+=1
print(lines)
(a) 2
(b) 1
(c) 3
(d) Error
Answer : A

13. What is the output of following code?
def myFunc() :
f=open (“Para.txt”, “r”)
count=0
x=f.read()
word=x.split()
for i in word:
     if (i!=“learning”):
          count=count+1
     print(count)
myFunc()
(a) 2
(b) 10
(c) 8
(d) Error
Answer : C

14. What is the output of following code?
def test():
f=open(“Para.TXT”)
n1=0
n2=0
while True:
     l=f.readline()
     if not l:
          break
     for i in l:
          if (i==‘E’ or i==‘e’):
               n1=n1+1
          elif(i==‘C’ or i==‘c’) :
               n2=n2+1
print(n1)
print(n2)
f.close()
(a) 8
     5
(b) 8
      4
(c) 3
     7
(d) Error
Answer : A

15. What is the output of following code?
def Func():
     with open(‘Para.txt’, ‘r’) as f :
          l=f.readlines()
f.close( )
print(l)
del l[3]
print (l)
f=open (‘Para.txt’, ‘w’)
f.writelines(l)
f.close( )
(a) Delete the 3rd word from file
(b) Delete the 4th word from file
(c) Delete the 3rd word from file at end
(d) Error
Answer : B

 
 
1. To open a file c:\scores.txt for reading, we use
a) Infile = open(“c:\scores.txt”, “r”)
b) infile = open(“c:\\scores.txt”, “r”)
c) infile = open(file = “c:\scores.txt”, “r”)
d) infile = open(file = “c:\\scores.txt”, “r”)
 
2. To open a file c:\scores.txt for writing, we use
a) outfile = open(“c:\scores.txt”, “w”)
b) outfile = open(“c:\\scores.txt”, “w”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)
 
3. What is a file? What are the two basic operations which are performed on a file?
 
4. What is the difference between a text file and a binary file?
 
5. Differentiate between ‘write’ mode and ‘append’ mode.
 
6. What different functions are available to write data in a text file?Describe each in brief.
 
7. What different functions are available to read data from a text file? Describe each in brief.
 
8. Why is it important to close a file?
 
9. In which mode should a file be opened:
a) To write data into an existing file.
b) To read data from a file
c) To create a new file and write data into it.
d) To write data into an existing file. If the file does not exist, then file should be created to write data into it.
 
10. Differentiate between seek() and tell().
 
11. Which functions are used to (i) rename a file, (ii) delete a file? In which module are these functions available?
 
12. What are the three standard input-output streams in Python?
 
13. Define the terms ‘pickling’ and ‘unpickling’.
 
14. What are different file opening modes for a text file in Python? Write,in brief, what does each mode do?
 
15. Consider the following code:
ch = "A"
f=open("data.txt",'a')
f.write(ch)
print(f.tell())
f.close()
What is the output if the file content before the execution of the program is the string "ABC"? (Note that" " are not the part of the string)
 
16. Write a single statement to display the contents of a text file named "abc.txt"
 
17. Assuming that a text file named TEXT1.TXT already contains some text written into it, write a function named vowelwords(), that reads the file TEXT1.TXT and creates a new file named TEXT2.TXT,
which shall contain only those words from the file TEXT1.TXT which
don’t start with an uppercase vowel (i.e., with ‘A’, ‘E’, ‘I’, ‘O’, ‘U’).
For example, if the file TEXT1.TXT contains
Carry Umbrella and Overcoat When It rains
Then the text file TEXT2.TXT shall contain Carry and When rains
 
18. Write a function in PYTHON to count and display the number of
words starting with alphabet ‘A’ or ‘a’ present in a text file
“LINES.TXT”. Example:
If the file “LINES.TXT” contains the following lines,
A boy is playing there. There is a playground.
An aeroplane is in the sky.
Are you getting it?
The function should display the output as 5.
 
19. Write a function show(n) that will display the nth character from the existing file “MIRA.TXT”. If the total characters present are less thann, then it should display “invalid n”.
 
20. Write a function CountHisHer() in PYTHON which reads the contents of a text file “Gender.txt” which counts the words His and Her (not case sensitive) present in the file.
For, example, if the file contains:
Pankaj has gone to his friend’s house. His friend’s name is Ravya. Her house is 12KM from here.
The function should display the output:
Count of His: 2
Count of Her: 1
 
21 Write the function definition for WORD4CHAR() in PYTHON to read the content of a text file FUN.TXT, and display all those words, which have four characters in it.
Example:
If the content of the file Fun.TXT is as follows:
When I was a small child, I used to play in the garden with my grand mom. Those days were amazingly fun filled and I remember all the moments of that time
The function WORD4CHAR() should display the following:
When used play with days were that time

 

Please click on below link to download CBSE Class 12 Computer Science File Handling Worksheet Set A

Practice Worksheets Class 12 Computer Science
CBSE Class 12 Computer Science All Chapters Worksheet
CBSE Class 12 Computer Science Arrays Worksheet
CBSE Class 12 Computer Science Binary Files Worksheet
CBSE Class 12 Computer Science Boolean Algebra Worksheet
CBSE Class 12 Computer Science C++ Worksheet Set A
CBSE Class 12 Computer Science C++ Worksheet Set B
CBSE Class 12 Computer Science Classes And Objects Worksheet
CBSE Class 12 Computer Science Communication Technology Worksheet
CBSE Class 12 Computer Science Computer Networks Worksheet Set A
CBSE Class 12 Computer Science Computer Networks Worksheet Set B
CBSE Class 12 Computer Science Computer Networks Worksheet Set C
CBSE Class 12 Computer Science Constructor And Destructor Worksheet Set A
CBSE Class 12 Computer Science Constructor And Destructor Worksheet Set A
CBSE Class 12 Computer Science Constructor And Destructor Worksheet Set B
CBSE Class 12 Computer Science Data Base Concept Worksheet
CBSE Class 12 Computer Science Data File Handling Worksheet
CBSE Class 12 Computer Science Data Management Worksheet Set A
CBSE Class 12 Computer Science Data Management Worksheet Set B
CBSE Class 12 Computer Science Data Management Worksheet Set C
CBSE Class 12 Computer Science Data Management Worksheet Set D
CBSE Class 12 Computer Science Data Management Worksheet Set E
CBSE Class 12 Computer Science File Handling Worksheet Set A
CBSE Class 12 Computer Science File Handling Worksheet Set B
CBSE Class 12 Computer Science File Handling Worksheet Set C
CBSE Class 12 Computer Science Function In Python Program Worksheet
CBSE Class 12 Computer Science Functions Worksheet Set A
CBSE Class 12 Computer Science Functions Worksheet Set B
CBSE Class 12 Computer Science Header Files Worksheet
CBSE Class 12 Computer Science Implementation of Queue Worksheet Set A
CBSE Class 12 Computer Science Implementation of Queue Worksheet Set B
CBSE Class 12 Computer Science Implementation of Stack Worksheet
CBSE Class 12 Computer Science Inheritance Worksheet Set A
CBSE Class 12 Computer Science Inheritance Worksheet Set B
CBSE Class 12 Computer Science Pointers Worksheet
CBSE Class 12 Computer Science Programming and Computational Thinking Worksheet Set A
CBSE Class 12 Computer Science Programming and Computational Thinking Worksheet Set B
CBSE Class 12 Computer Science Programming and Computational Thinking Worksheet Set C
CBSE Class 12 Computer Science Programming and Computational Thinking Worksheet Set D
CBSE Class 12 Computer Science Programming and Computational Thinking Worksheet Set E
CBSE Class 12 Computer Science Programming and Computational Thinking Worksheet Set F
CBSE Class 12 Computer Science Python Worksheet
CBSE Class 12 Computer Science Recursion Worksheet
CBSE Class 12 Computer Science Revision Worksheet
CBSE Class 12 Computer Science Society Law and Ethics Worksheet Set A
CBSE Class 12 Computer Science Society Law and Ethics Worksheet Set B
CBSE Class 12 Computer Science Society Law and Ethics Worksheet Set C
CBSE Class 12 Computer Science Society Law and Ethics Worksheet Set D
CBSE Class 12 Computer Science Society Law and Ethics Worksheet Set E
CBSE Class 12 Computer Science Sql Worksheet Set A
CBSE Class 12 Computer Science Sql Worksheet Set B
CBSE Class 12 Computer Science Using Python Libraries Worksheet
CBSE Class 12 Computer Science Worksheet Set A Solved
CBSE Class 12 Computer Science Worksheet Set B Solved
CBSE Class 12 Computer Science Worksheet Set C Solved
CBSE Class 12 Computer Science Worksheet Set D Solved
CBSE Class 12 Computer Science Worksheet Set E Solved
CBSE Class 12 Computer Science Worksheet Set F Solved

More Study Material

CBSE Class 12 Computer Science File Handling Worksheet

The above practice worksheet for File Handling has been designed as per the current syllabus for Class 12 Computer Science released by CBSE. Students studying in Class 12 can easily download in Pdf format and practice the questions and answers given in the above practice worksheet for Class 12 Computer Science on a daily basis. All the latest practice worksheets with solutions have been developed for Computer Science by referring to the most important and regularly asked topics that the students should learn and practice to get better scores in their examinations. Studiestoday is the best portal for Printable Worksheets for Class 12 Computer Science students to get all the latest study material free of cost.

Worksheet for Computer Science CBSE Class 12 File Handling

Teachers of studiestoday have referred to the NCERT book for Class 12 Computer Science to develop the Computer Science Class 12 worksheet. If you download the practice worksheet for the above chapter daily, you will get better scores in Class 12 exams this year as you will have stronger concepts. Daily questions practice of Computer Science printable worksheet and its study material will help students to have a stronger understanding of all concepts and also make them experts on all scoring topics. You can easily download and save all revision Worksheets for Class 12 Computer Science also from www.studiestoday.com without paying anything in Pdf format. After solving the questions given in the practice sheet which have been developed as per the latest course books also refer to the NCERT solutions for Class 12 Computer Science designed by our teachers

File Handling worksheet Computer Science CBSE Class 12

All practice paper sheet given above for Class 12 Computer Science have been made as per the latest syllabus and books issued for the current academic year. The students of Class 12 can be assured that the answers have been also provided by our teachers for all test paper of Computer Science so that you are able to solve the problems and then compare your answers with the solutions provided by us. We have also provided a lot of MCQ questions for Class 12 Computer Science in the worksheet so that you can solve questions relating to all topics given in each chapter. All study material for Class 12 Computer Science students have been given on studiestoday.

File Handling CBSE Class 12 Computer Science Worksheet

Regular printable worksheet practice helps to gain more practice in solving questions to obtain a more comprehensive understanding of File Handling concepts. Practice worksheets play an important role in developing an understanding of File Handling in CBSE Class 12. Students can download and save or print all the printable worksheets, assignments, and practice sheets of the above chapter in Class 12 Computer Science in Pdf format from studiestoday. You can print or read them online on your computer or mobile or any other device. After solving these you should also refer to Class 12 Computer Science MCQ Test for the same chapter.

Worksheet for CBSE Computer Science Class 12 File Handling

CBSE Class 12 Computer Science best textbooks have been used for writing the problems given in the above worksheet. If you have tests coming up then you should revise all concepts relating to File Handling and then take out a print of the above practice sheet and attempt all problems. We have also provided a lot of other Worksheets for Class 12 Computer Science which you can use to further make yourself better in Computer Science

Where can I download latest CBSE Practice worksheets for Class 12 Computer Science File Handling

You can download the CBSE Practice worksheets for Class 12 Computer Science File Handling for the latest session from StudiesToday.com

Can I download the Practice worksheets of Class 12 Computer Science File Handling in Pdf

Yes, you can click on the links above and download chapter-wise Practice worksheets in PDFs for Class 12 for Computer Science File Handling

Are the Class 12 Computer Science File Handling Practice worksheets available for the latest session

Yes, the Practice worksheets issued for File Handling Class 12 Computer Science have been made available here for the latest academic session

How can I download the File Handling Class 12 Computer Science Practice worksheets

You can easily access the links above and download the Class 12 Practice worksheets Computer Science for File Handling

Is there any charge for the Practice worksheets for Class 12 Computer Science File Handling

There is no charge for the Practice worksheets for Class 12 CBSE Computer Science File Handling you can download everything free

How can I improve my scores by solving questions given in Practice worksheets in File Handling Class 12 Computer Science

Regular revision of practice worksheets given on studiestoday for Class 12 subject Computer Science File Handling can help you to score better marks in exams

Are there any websites that offer free Practice test papers for Class 12 Computer Science File Handling

Yes, studiestoday.com provides all the latest Class 12 Computer Science File Handling test practice sheets with answers based on the latest books for the current academic session

Can test sheet papers for File Handling Class 12 Computer Science be accessed on mobile devices

Yes, studiestoday provides worksheets in Pdf for File Handling Class 12 Computer Science in mobile-friendly format and can be accessed on smartphones and tablets.

Are practice worksheets for Class 12 Computer Science File Handling available in multiple languages

Yes, practice worksheets for Class 12 Computer Science File Handling are available in multiple languages, including English, Hindi