wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Computer science file handling Grade 12 cbse

Total questions: 80

Worksheet time: 38mins

Name
Class
Date
1.

What is the process of reading data from a text file called?

a)

data extraction

b)

text scanning

c)

file reading

d)

file parsing

2.

How can you open a text file in read mode in Python?

a)

open('file.txt', 'r')

b)

open('file.txt', 'w')

c)

open('file.txt', 'x')

d)

open('file.txt', 'a')

3.

What is the main advantage of using binary files over text files?

a)

Efficiency in storage and processing speed

b)

Higher level of security for sensitive data

c)

Easier to edit and modify the content

d)

Better compatibility with different operating systems

4.

Explain the concept of newline in CSV files.

a)

A newline in CSV files is represented by the character sequence '\v'.

b)

A newline in CSV files is represented by the character sequence '\n'.

c)

A newline in CSV files is represented by the character sequence '\r'.

d)

A newline in CSV files is represented by the character sequence '\t'.

5.

What is the purpose of the delimiter in CSV files?

a)

To format the text in bold

b)

To add color to the file

c)

To separate individual fields or columns within each row

d)

To encrypt the data

6.

How can you write data to a text file in Python?

a)

Skip closing the file after writing

b)

Open the file in read mode: file = open('filename.txt', 'r')

c)

Open the file in write mode: file = open('filename.txt', 'w') Write data to the file: file.write('Hello, World!') Close the file: file.close()

d)

Use file.append() method to write data

7.

In CSV files, what does each row represent?

a)

Each row represents a single record or data entry.

b)

Each row represents a header

c)

Each row represents a paragraph

d)

Each row represents a column

8.

What are the different modes in which you can open a file in Python?

a)

x

b)

b

c)

z

d)

'r', 'w', 'a', 'r+', 'w+', 'a+'

9.

How can you handle errors while working with files in Python?

a)

Use if-else statements to handle errors when working with files.

b)

Use try-except blocks in Python to handle errors when working with files.

c)

Ignore errors and continue execution when working with files.

d)

Manually terminate the program when errors occur while working with files.

10.

What is the difference between reading and writing to a file?

a)

Reading retrieves data, writing adds or updates data.

b)

Reading deletes data, writing appends data.

c)

Reading updates data, writing retrieves data.

d)

Reading adds data, writing retrieves and updates data.

11.

Explain the process of writing data to a binary file.

a)

The process involves opening the binary file, converting data to binary format, writing the binary data, and then closing the file.

b)

Skipping the step of closing the file after writing

c)

Writing the data in reverse order

d)

Converting data to text format before writing

12.

What is the significance of the 'rb' mode when opening a binary file?

a)

It indicates that the file is being opened in write mode for binary data

b)

It signifies that the file is being opened in append mode for binary data

c)

It specifies that the file is being opened in read mode for text data

d)

It signifies that the file is being opened in read mode specifically for binary data.

13.

How can you specify a custom delimiter while reading a CSV file in Python?

a)

csv.reader(file, delim='custom_delimiter')

b)

csv.reader(file, delimiter='custom_delimiter')

c)

csv.reader(file, delimiter='custom_delimiter')

d)

csv.reader(file, delimiter='custom_delim')

14.

Discuss the importance of closing a file after performing operations on it.

a)

Closing a file after performing operations on it helps release system resources and ensures data integrity and security.

b)

Leaving a file open improves system performance

c)

Not closing a file enhances file security

d)

Closing a file can lead to data loss

15.

What is the purpose of using 'rb' mode when opening a binary file in Python?

a)

It indicates that the file is being opened in write mode for binary data

b)

It signifies that the file is being opened in append mode for binary data

c)

It specifies that the file is being opened in read mode for text data

d)

It signifies that the file is being opened in read mode specifically for binary data.

16.

What is the purpose of the 'a' mode when opening a file in Python?

a)

It indicates that the file is being opened in append mode for text data

b)

It signifies that the file is being opened in read mode for binary data

c)

It specifies that the file is being opened in write mode for text data

d)

It signifies that the file is being opened in read mode specifically for text data.

17.

Explain the difference between 'r' and 'w' modes when opening a file in Python.

a)

'r' mode opens the file in read-only mode, while 'w' mode opens the file in write-only mode.

b)

'r' mode opens the file in write-only mode, while 'w' mode opens the file in read-only mode.

c)

'r' mode opens the file in read and write mode, while 'w' mode opens the file in write-only mode.

d)

'r' mode opens the file in read-only mode, while 'w' mode opens the file in read and write mode.

18.

the module to be imported to work with binary files in python

(a)  

19.

Explain the difference between 'a' and 'w' modes when opening a file in Python.

a)

'a' mode opens the file in append mode, while 'w' mode opens the file in write-only mode.

b)

'a' mode opens the file in write-only mode, while 'w' mode opens the file in read-only mode.

c)

'a' mode opens the file in append mode, while 'w' mode opens the file in write-only mode.

d)

'a' mode opens the file in read and write mode, while 'w' mode opens the file in write-only mode.

20.

What is the difference between appending and writing to a file?

a)

Appending adds data at the end of the file, while writing overwrites existing data.

b)

Appending deletes data, while writing updates data.

c)

Appending updates data, while writing retrieves data.

d)

Appending adds data, while writing retrieves and updates data.

21.

What will be the output-

f=open('abc.txt','a')

text="xyz"

f.write(text)

f.close()

a)

Writing into the file without erasing old content

b)

Writing into the file by erasing old content

c)

reading from the file without erasing old content

d)

reading from the file by erasing old content

22.

Mode in the following program to open file for writing in a mode where new data will be added at the end of old data

file =open("poem.txt","__")

a)

r

b)

w

c)

a

d)

r+

23.

Choose the correct statement to close a file stream named myfile:

a)

myfile.terminate()

b)

myfile.end()

c)

myfile.close()

d)

myfile.remove()

24.

Fill in the blank with appropriate statement.

(a)  

25.

Write the appropriate statement in the blank.

(a)  

26.

Which statement(s) is/are true to open a binary file "Record.dat" for reading and writing.

a)

file =open("Record.dat","wb")

b)

file =open("Record.dat","rb")

c)

file =open("Record.dat","ab")

d)

file =open("Record.dat","rb+")

27.

Which function read single line at a time?

a)

read()

b)

read(n)

c)

readline()

d)

readlines()

28.

Which file is not binary file?

a)

student.mp4

b)

student.jpeg

c)

student.csv

d)

student.exe

29.

Where files are store permanently?

a)

RAM

b)

Hard Disk

c)

Cache memory

d)

None of these

30.

Which function is used to write multiple lines in text file?

a)

write()

b)

writelines()

c)

lines()

d)

print()

31.
Appending to a file means adding extra data into the file.
a)
True
b)
False
32.

Which statement(s) is/are true to open a binary file "Record.dat" for reading and writing ?

a)

file =open("Record.dat","wb")

b)

file =open("Record.dat","rb")

c)

file =open("Record.dat","ab")

d)

file =open("Record.dat","rb+")

33.

Q.2 Which of the following statements are not true regarding the opening modes of a file?

a)

When you open a file for reading, if the file does not exist, an error occurs.

b)

When you open a file for writing, if the file does not exist, an error occurs

c)

When you open a file for writing, if the file does not exist, a new file is created.

d)

When you open a file for writing, if the file exists, the existing file is overwritten with the new file.

34.

Q.3 Which module is used to work with binary files?

a)

CSV module

b)

pickle module

c)

math module

d)

binary module

35.

Function used to write data in binary format

a)

write()

b)

output()

c)

load()

d)

dump()

36.
Which of the following is not a method of opening files?
a)
Replace
b)
Append
c)
Write
d)
Read
37.
What is the data type of data read from a file?
a)
String
b)
Integer
c)
Real
d)
Boolean
38.
Reading from a file often involves using...
a)
A loop
b)
An condition
c)
Comments
39.



(a)  

40.

see the program and fill in the blank with correct statement.

(a)  

41.

write statement to use the required module for working with comma separated values (csv) files.

(a)  

42.

Write the appropriate statement in the blank.

(a)  

43.

Information stored on a storage device with a specific name is called a _______________

a)

tuple

b)

array

c)

dictionary

d)

file

44.

To read the next line of the file from a file object called F_H, we use

a)

F_H.readlines()

b)

F_H.read(all)

c)

F_H.readline()

d)

F_H.read()

45.

Which of the following format of files can be created programmatically through python to store some data

a)

Data File

b)

Video File

c)

Binary File

d)

Text File

46.

To read the remaining line of the file from a file object called F_H, we use

a)

F_H.readlines()

b)

F_H.read.remaining()

c)

F_H.readline()

d)

F_H.read(remaining)

47.

The readlines() method returns_______

a)

String

b)

A list of characters

c)

A list of lines

d)

Index of lines in as a list

48.

Which of the following code of line is with error?

a)

Out = open("d:\\PyPro\\test.txt", "r")

b)

Out = open(r"d:\PyPro\test.txt", "r")

c)

Out = open(path="d:\\PyPro\\test.txt", "r")

d)

Out = open("test.txt", "r")

49.

Which of the statement is not true regarding the opening mode of a file?

a)

When you open a file for reading, if the file does not exist, an error occurs.

b)

When you open a file for writing, if the file does not exist, an error occurs.

c)

When you open a file for reading in r+ mode, if the file does not exist, an error occurs.

d)

When you open a file for reading in w+ mode, if the file does not exist, a new file is created.

50.

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

51.

EOL stands for

a)

End Of Line

b)

End Of List

c)

End of Lines

d)

End Of Location

52.

In f=open(“data.txt”, “r”), r refers to __________.

a)

File handle

b)

File object

c)

File Mode

d)

Buffer

53.

Q1. Given the following file opened as song_file:


I can't write one song that's not about you

Can't drink without thinkin' about you

Is it too late to tell you that

Everything means nothing if I can't have you?


What is the result of

print(song_file.read(4)) ?

a)

I ca

b)

I can

I c

I can't write one song that's not about you

Can't drink without thinkin' about

c)

I c

d)

you

Is it too late to tell you that

Everything means nothing if I can't have you?

54.

Given the following file opened as song_file:


I can't write one song that's not about you

Can't drink without thinkin' about you

Is it too late to tell you that

Everything means nothing if I can't have you?


What is the result of

print(text_file.readlines()[1]) ?

a)

I can't write one song that's not about you

b)

Can't drink without thinkin' about you

I can't write one song that's not about you

Can't drink without thinkin' about

c)

you

Is it too late to tell you that

Everything means nothing if I can't have you?

d)

I

55.

What is the best way to read an entire file into a list of strings?

a)

.read()

b)

.readline()

c)

.readlines()

d)

.read(all)

56.

What is the best way to read an entire file into a single string?

a)

.read()

b)

.readline()

c)

.readlines()

d)

.read(all)

57.

What is the best way to read the first line of a file?

a)

.read()

b)

.readline()

c)

.readlines()

d)

.read(all)

58.

When reading text files, what are the hidden characters typically at the end of each line?

a)

\n

b)

»

c)

#

d)

@

59.

If I want to add to the end of a text file, I should:

a)

MyCipher = open("MyCipher.txt", "w")

b)

MyCipher = open("MyCipher.txt", "a")

c)

MyCipher = open("MyCipher.txt", "w+")

d)

MyCipher = open("MyCipher.txt", "s")

60.

Which of these will generate an error?

a)

MyCipher.write("writing")

b)

MyCipher..write(writing)

c)

MyCipher.write("writing",writing)

d)

MyCipher.readline()

61.

Which file execute faster?

a)

Text file

b)

Binary file

c)

CSV file

62.

The default file - open mode is (a)   mode.

63.

How do you change the file position to an offset value from the start?

a)

fp.seek(offset, 0)

b)

fp.seek(offset, 1)

c)

fp.seek(offset, 2)

d)

none of the mentioned

64.

4. What will be the ouput -

f=open('abc.txt','w')

x=f.read()

f.close()

print(x)

a)

Error(not readable)

b)

Error(not writable)

c)

It will read all the data of the file.

d)

None

65.

What will be the output of the following Python code?

a)

True

b)

False

c)

None

d)

error

66.

7. Name the module that has to be imported to write a csv file.

a)

Pickle module

b)

CSV module

c)

csv module

d)

Csv module

67.

10. ______ is the extension of binary files

a)

.txt

b)

.bin

c)

.dat

d)

.Dat

68.

To read 18 characters from the file object fobj , the correct syntax is ____________.

a)

fobj.readlines(18)

b)

fobj.readchar(18)

c)

fobj.read(18)

d)

fobj.readline(18)

69.

Mention the data type of variable check in the following statements?

a. check=f.read()

b. check=f.readline()

c. check=f.readlines()

a)

a. str b. str c. list

b)

a. list b. str c. list

c)

a. str b. list c. list

d)

a. str b. list c. str

70.

______________ is the process of converting Python object hierarchy into a byte stream so that it can be written to a file

a)

Conversion

b)

Translation

c)

Serialization

d)

unpickling

71.

Raju created a binary file, student.dat file using the file handle fh. He wants to enter the details of the student into the student.dat file in the form of list. Help him to complete the code.

import ____________ # line 1

f=open('emp.dat','wb') # line 2

rec1=[101,'Sridhar','15 yrs',560] # line 3

rec2=[102,'Sujata','15 yrs',580] # line 4


_____________________________ # line 5

_____________________________ # line 6


f.close() # line 7

a)

line 1: csv, line 5: f.write(rec1) , line 6: f.writerecord(rec2,f)

b)

line 1: pickle, line 5: f.dump(rec1) , line 6: f.dump(rec2,f)

c)

line 1: pickle, line 5: f,dump(rec1), line 6: f.dump(rec2)

d)

line 1: pickle, line 5: pickle.dump(rec1,f) , line 6: pickle.dump(rec2,f)

72.

The __________ function returns the current position of file pointer in the file.

a)

tell()

b)

loc

c)

seek()

d)

pos()

73.

The __________ function changes the position of the file pointer by placing the file pointer at the specified position in an open file

a)

tell()

b)

loc

c)

seek()

d)

pos()

74.

The default delimiter of the CSV file is ____________.

a)

tab

b)

comma

c)

colon

d)

filter

75.

To create a csv file sales.csv, the correct syntax is _____________

a)

f=open('sales.csv', 'w')

b)

f=open('sales.csv', 'r')

c)

f=open('sales.csv', 'w+')

d)

f=open('sales.csv', 'a')

76.

_________________ and __________ are the two objects associated with the csv module to reading and write onto a CSV file.

a)

reader() and writer()

b)

read() and write()

c)

dump() and load()

d)

write() and writelines()

77.

_________________ function is used to write single row at a time.

a)

writerow()

b)

writerows()

c)

writerecords()

d)

writelines()

78.

_________________ method writes all given rows to the csv file.

a)

writerow()

b)

writerows()

c)

writeln()

d)

writelines()

e)

writeline()

79.

To create the reader object, the correct syntax is __________.

[Assume that the salesdet.csv file is opened in reading mode in the file handle fh.

a)

salesdet_reader=csv.reader(fh)

b)

salesdet_reader=csvreader(fh)

c)

salesdet_reader=csv.read(fh)

d)

salesdet_reader=csvreader.fh

80.

Which file is not binary file?

a)

student.mp4

b)

student.jpeg

c)

student.csv

d)

student.exe