Questions

1 Marks Each

🎯

Test yourself on this topic

20 questions · timed · auto-graded

Question 11 Mark
A text file “Quotes.Txt” has the following data written in it:
Living a life you can be proud of
Doing your best
Spending your time with people and activities that are important to you
Standing up for things that are right even when it’s hard
Becoming the best version of you.
Write the output of the given program.

Answer
ife y
View full question & answer
Question 21 Mark
Assume that file “tear.txt”, already contain “I love my India” in the file. What will be the output of the given program:

Answer
13
View full question & answer
Question 31 Mark
Assume that file “tear.txt”, already contain “I love my India” in the file. What will be the output of the given program:

View full question & answer
Question 51 Mark
Observe the following code and answer the questions that follow:

(i) What type (Text/Binary) of file is Mydata?
(ii) Fill the Blank 1 with statement to write “ABC” in the file “Mydata”.

Answer
(i) Text File (default mode)
(ii) File.write(“ABC”)
View full question & answer
Question 61 Mark
Differentiate between file modes r+ and rb+ with respect to Python.
Answer
Difference
r It opens the file in reading and writing.
rb+ It opens the file in reading and writing for binary format.
View full question & answer
Question 71 Mark
Write a statement in python to perform the following operations: • To open a text file “MYPET.TXT” in write mode. • To open a text file “MYPET.TXT” in read mode.
View full question & answer
Question 81 Mark
Write a statement in Python to open a text file STORY.TXT so that new contents can be added at the end of it.
View full question & answer
Question 91 Mark
Nancy intends to position the file pointer to the beginning of a text file. Write Python statement for the same assuming F is the Fileobject.
Answer
F.seek(0)
View full question & answer
Question 101 Mark
How relative path is different from absolute path.
Answer
The absolute path is the full path from we want to open/create the file. The relative path is the path to some file with respect to your current working directory.
View full question & answer
Question 111 Mark
Write the difference between “r” and “rb” mode.
Answer
rIt opens the file in reading mode only in text format.
rbIt opens the file reading only in binary format.
View full question & answer
Question 121 Mark
What is .csv file?
Answer
Comma Separated Values. It is a simple file format which store into the tabular format. This format file can be open in notepad or spreadsheet. It works better as its takes less memory space and faster in data manipulation.
View full question & answer
Question 161 Mark
Difference between tell() and seek().
Answer
Tell(). It returns the current position of the file object (Integer value). Seek(). It position the file object at the specified location.
View full question & answer
Question 171 Mark
Differentiate the following:(a) f = open('diary.txt', 'r') (b) f = open('diary.txt', 'w')
Answer
(a) It opens the file in reading mode only in text format.(b) It opens the file in writing mode only in text format. If the file exists, then it erases the previous data.
View full question & answer
Question 181 Mark
Write the difference between the following. (a) f = open('diary.txt', 'a') (b) f = open('diary.txt', 'w')
Answer
(a) It will open the file in append mode and data will be added at the end of the file only. (b) It will open the file in write mode if file already exists then previous data will be erased.
View full question & answer
Question 191 Mark
Write a statement in Python to open a text file STORY.TXT, so that the new contents can be added at the end of it.
Answer
File = open("STORY.TXT","w")
View full question & answer
Question 201 Mark
What will be the output of the following code snippet? If we assume that file contains the given text:
Str="CBSE Class XII Python Examination 2020"

Answer
Name of the file: myfile.txt

View full question & answer
1 Marks Each - Computer Science STD 12 Commerce Questions - Vidyadip