REV 5 - Q WITH ANS__ Text,CSV and Binary Files 13.09.24
REV 5 - Q WITH ANS__ Text,CSV and Binary Files 13.09.24
General Instructions:
● This question paper contains 37 questions.
● All questions are compulsory. However, internal choices have been
provided in some questions. Attempt only one of the choices in such
questions
● The paper is divided into 5 Sections- A, B, C, D and E.
● Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
● Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
● Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
● Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
● Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
● All programming questions are to be answered using Python Language only.
● In case of MCQ, text of the correct answer should also be written.
Ans : 22
A) To read two characters from a file object "file_read"
4.
(a) file_read.read(2) (b) file_read(2)
(c) file_read(read,2) (d) file_read.readlines(2) (1)
A) Assume that file “tear.txt”, already contain “I love my India” in the file. What will be the
6.
output of the given program:
(1)
Ans : 13
B) To read the content of the file as a string via a file object "f"
(a) f.read(2) (b) f.read() (c) f=file.readline() (d) f.readlines()
Page: 2/6
A) A text file “Quotes.Txt” has the following data written in it:
7.
Living a life you can be proud of
Doing your best
Spending your time with people and activities that are important to (1)
you Standing up for things that are right even when it’s hard
Becoming the best version of you.
Ans : ife y
B) List any 2 example text files.
Ans : .txt,.csv,.py,json etc.,
A) Which type of file does not have delimiters?
8. (1)
Ans : Binary File
B) The process of converting the structure to a byte stream before writing to the file is known
as _________.
Ans : Pickling
A) The process of converting byte stream back to the original structure is known as ____
9.
B) Raman open a file in read mode, but the file doesn’t exist in the folder. Python raised an
error for the code. What type of error will be shown? (1)
B) The prefix ______ in front of a string makes it raw string that is no special meaning
attached to any character
A) Pickling is otherwise known as ________________
1
1.
(1)
B) CSV files are opened with __________argument to supress EOL translation
31. List the difference between Text, Binary and CSV files
(3)
Q No. Section-D ( 4 x 4 = 16 Marks) Mark
s
32. Write a python program to search and display the record of the student (4)
from a binary file “Student.dat” containing students records (Rollno,
Name and Marks). Roll number of the student to be searched will be
entered by the user.
Krishna is confused in Python code given below. Please help him to answer
34.
the following questions.
(4)
(a) Which line in the above code check for capital letter?
(b) Which line in the above code read the file “story. txt”?
(c) Which line in the above code does not affect the execution of program?
(d) Which line is the above code coverts capital letter to small letter?
(e) Which line is the above code opens the file in write mode?
(f) Which line is the above code saves the data?
(g) Which line(s) is/are the part of selection statement.
(h) Which line(s) is/are used to close story1.txt?
Page: 4/6
35. A csv file "Happiness.csv" contains the data of a survey. Each record of the file contains
the following data:
● Name of a country
● Population of the country
● Sample Size (Number of persons who participated in the survey in that country)
● Happy (Number of persons who accepted that they were Happy)
Write the following Python functions to perform the specified operations on this file:
(I) Read all the data from the file in the form of a list and display all those
records for which the population is more than 5000000.
(II) Count the number of records in the file.
You, as a programmer of the company, have been assigned to do this job for Surya.
(I) Write a function to input the data of a candidate and append it in a binary file.
(II) Write a function to update the data of candidates whose experience is more than
10 years and change their designation to "Senior Manager".
(III) Write a function to read the data from the binary file and display the data of all
those candidates who are not "Senior Manager".
Neha is making software on “Items & their prices” in which various records are to be
37. stored/retrieved in STORE.CSV data file. It consists some records (Item & Price). She has
written the following code in python. As a programmer, you have to help her to successfully
execute the program
def ShowRecord():
with open(“STORE.CSV”,”r”) as NI:
NewItem=csv._______ (NI) # Statement-5
Page: 5/6
for rec in NewItem:
print(rec[0], “#”, rec[1])
#main-code
AddItem(“Sugar”, 38.00)
AddItem(“Rice”, 48.50)
ShowRecord() # Statement-6
Page: 6/6