Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PCEP Questions

Total questions: 26

Worksheet time: 13mins

Name
Class
Date
1.
Which of the following is not a method of opening files?
a)
Replace
b)
Append
c)
Write
d)
Read
2.
Appending to a file means adding extra data into the file.
a)
True
b)
False
3.
What is the last action that must be performed on a file?
a)
Close
b)
Save
c)
End
d)
Write
4.
What is the data type of data read from a file?
a)
String
b)
Integer
c)
Real
d)
Boolean
5.
Reading from a file often involves using...
a)
A loop
b)
An condition
c)
Comments
6.
Appending data to a file places it at the start of the file.
a)
False
b)
True
7.

How do you insert something on a new line in a file?

a)

\n

b)

You cannot do this

c)

type the content on the line below

d)

write.newline('x')

8.

What does 'strip' do?

a)

Removes the contents of the whole file

b)

Removes extra data at the beginning/end of a string

c)

Adds in metadata

d)

Splits the file

9.

Select the statement to open a file named MYDATA.dat in read binary mode. Let the file object name be myfile.

a)

myfile=open("MYDATA.dat","rb")

b)

myfile=open("MYDATA.dat","r+")

c)

myfile=open("MYDATA.dat","r")

10.

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+

11.

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

a)

myfile.terminate

b)

myfile.end()

c)

myfile.close

d)

myfile.remove()

e)

myfile.close()

12.

What will be the ouput -

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

x=f.read()

f.close()

print(x

a)

It will read all the data of the file.

b)

none

c)

Error(not writable)

d)

Error(not readable)

13.

What will be the output-

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

text="xyz"

f.write(text)

f.close()

a)

Writing into the file by erasing old content

b)

Writing into the file without erasing old content

c)

reading from the file by erasing old content

d)

reading from the file without erasing old content

14.

?

a)

true

b)

false

c)

none

d)

Error

15.

piši bez space

(a)  

16.

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)

a

c)

w

d)

x

17.

To read two characters from a file object infile, we use ____________

a)

infile.readlines()

b)

infile.readline()

c)

infile.read()

d)

infile.read(2)

18.

When reading a file using the file object, what method is best for reading the entire file into a single string?

a)

.readline()

b)

.read()

c)

.read_file_to_str()

d)

.readlines()

19.

Given the file dog_breeds.txt, which of the following is the correct way to open the file for reading as a text file? Select all that apply. VIŠE ODGOVORA..

a)

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

b)

open('dog_breeds.txt')

c)

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

d)

open('dog_breeds.txt')

e)

open('dog_breeds.txt', 'rb')

20.

Which of the following statements are 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.

21.

Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?

a)

n = file.read()

b)

file.read(n)

c)

file.readline(n)

d)

file.readlines()

22.

Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?

a)

A. tmpfile.read(n)

b)

B. tmpfile.read()

c)

C. tmpfile.readline()

d)

D. tmpfile.readlines()

23.

Which of the following commands can be used to read the next line in a file using the file object <tmpfile>

a)

D. tmpfile.readlines()

b)

A. tmpfile.read(n)

c)

B. tmpfile.read()

d)

C. tmpfile.readline()

24.

Which of the following commands can be used to read the remaining lines in a file using the file object <tmpfile>?

a)

tmpfile.read(n)

b)

tmpfile.read()

c)

tmpfile.readlines()

d)

tmpfile.readline()

25.

What does the <readlines()> method returns?

a)

str

b)

a list of lines

c)

list of single characters

d)

list of integers

26.

txt = input("Enter your input: ")

print ("Received input is : ", txt)

a)

All

b)

Enter your input: [x*5 for x in range(2,10,2)]

Received input is : [10, 20, 30, 40]

c)

Enter your input: Hello Viewers

Received input is : Hello Viewers

d)

None of the above