WorksheetsPCEP Questions
Total questions: 26
Worksheet time: 13mins
How do you insert something on a new line in a file?
\n
You cannot do this
type the content on the line below
write.newline('x')
What does 'strip' do?
Removes the contents of the whole file
Removes extra data at the beginning/end of a string
Adds in metadata
Splits the file
Select the statement to open a file named MYDATA.dat in read binary mode. Let the file object name be myfile.
myfile=open("MYDATA.dat","rb")
myfile=open("MYDATA.dat","r+")
myfile=open("MYDATA.dat","r")
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","__")
r
w
a
r+
Choose the correct statement to close a file stream named myfile:
myfile.terminate
myfile.end()
myfile.close
myfile.remove()
myfile.close()
What will be the ouput -
f=open('abc.txt','w')
x=f.read()
f.close()
print(x
It will read all the data of the file.
none
Error(not writable)
Error(not readable)
What will be the output-
f=open('abc.txt','a')
text="xyz"
f.write(text)
f.close()
Writing into the file by erasing old content
Writing into the file without erasing old content
reading from the file by erasing old content
reading from the file without erasing old content
?
true
false
none
Error
piši bez space
(a)
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","__")
r
a
w
x
To read two characters from a file object infile, we use ____________
infile.readlines()
infile.readline()
infile.read()
infile.read(2)
When reading a file using the file object, what method is best for reading the entire file into a single string?
.readline()
.read()
.read_file_to_str()
.readlines()
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..
open('dog_breeds.txt', 'r')
open('dog_breeds.txt')
open('dog_breeds.txt', 'w')
open('dog_breeds.txt')
open('dog_breeds.txt', 'rb')
Which of the following statements are true regarding the opening modes of a file?
When you open a file for reading, if the file does not exist, an error occurs.
When you open a file for writing, if the file does not exist, an error occurs.
When you open a file for writing, if the file does not exist, a new file is created.
When you open a file for writing, if the file exists, the existing file is overwritten with the new file.
Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?
n = file.read()
file.read(n)
file.readline(n)
file.readlines()
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. tmpfile.read(n)
B. tmpfile.read()
C. tmpfile.readline()
D. tmpfile.readlines()
Which of the following commands can be used to read the next line in a file using the file object <tmpfile>
D. tmpfile.readlines()
A. tmpfile.read(n)
B. tmpfile.read()
C. tmpfile.readline()
Which of the following commands can be used to read the remaining lines in a file using the file object <tmpfile>?
tmpfile.read(n)
tmpfile.read()
tmpfile.readlines()
tmpfile.readline()
What does the <readlines()> method returns?
str
a list of lines
list of single characters
list of integers
txt = input("Enter your input: ")
print ("Received input is : ", txt)
All
Enter your input: [x*5 for x in range(2,10,2)]
Received input is : [10, 20, 30, 40]
Enter your input: Hello Viewers
Received input is : Hello Viewers
None of the above
