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
Please click on below link to download CBSE Class 12 Computer Science File Handling Worksheet Set A
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
You can download the CBSE Practice worksheets for Class 12 Computer Science File Handling for the latest session from StudiesToday.com
Yes, you can click on the links above and download chapter-wise Practice worksheets in PDFs for Class 12 for Computer Science File Handling
Yes, the Practice worksheets issued for File Handling Class 12 Computer Science have been made available here for the latest academic session
You can easily access the links above and download the Class 12 Practice worksheets Computer Science for File Handling
There is no charge for the Practice worksheets for Class 12 CBSE Computer Science File Handling you can download everything free
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
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
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.
Yes, practice worksheets for Class 12 Computer Science File Handling are available in multiple languages, including English, Hindi