0% found this document useful (0 votes)
62 views

REV 5 - Q WITH ANS__ Text,CSV and Binary Files 13.09.24

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

REV 5 - Q WITH ANS__ Text,CSV and Binary Files 13.09.24

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Pushpathur, Palani – 624 618

Class: XII Session: 2023-24


Computer Science (083) – Revision Test 05
Maximum Marks: 70 Time
Allowed: 3 Hrs

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.

Q Section-A (21 x 1 = 21 Marks) Mark


No. s
A) To open a file "c:marks.txt" for reading, we use
1. (1)
(a) file_read = open("c:marks.txt", "r")
(b) file_read = open("c:\\marks.txt", "r")
(c) file_read = open(file = "c:marks.txt", "r")
(d) file_read = open(file = "c:marks.txt", "r")

B) What is the use of tell() method in Python?


(a) returns the current position of record pointer within the file
(b) returns the end position of record pointer within the file
(c) returns the current position of record pointer within the line
(d) none of the above
A) Which of the following commands can be used to read "n" number of characters from a
2.
file using the file object <File>?
(a) File.read(n) (b) N = file.read() (c) File.readline(n) (d) File.readlines()

B) What is the correct syntax of open() function? (1)


(a) File = open(file_name[, access_mode][, buffering])
(b) File object = open(file_name [, access_mode][,buffering])
(c) File object = open(file_name)
(d) None of the above
A) Write the coding to display the content of file "welcome.txt".
3.
Ans : f=open(“welcome.txt”,”r”)
Print(f.read()) (1)
Or
Page: 1/6
f=open(“welcome.txt”,”r”)
c=f.read()
Print(c)

B) Write the output of the given program:

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)

B) seek() method in files used for ___________


Ans: Set the file’s current position at the offset
5. A)What does the <readlines()> method returns?
(a) Str (b) A list of lines (c) List of single characters (d) List of integers (1)

B) Differentiate the following:


(a) f = open('diary.txt', 'r')
Ans : Opens the file in reading mode only in text format
(b) f = open('diary.txt', 'w')
Ans : Opens the file in writing mode only in text format. If the file
exist then it erase the previous data

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.

Write the output of the following:

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)

1 A) Write the missing statement to complete the following code:


0. file = open("example.txt", "r")
data = file.read(100)
#Move the file pointer to the beginning of the file (1)
next_data = file.read(50)
file.close()

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

A) Which of the following statement is incorrect in the context of binary files?


12.
Q No. a. Information is stored in theSection-C
same format
( 3 in
x 3which the information is held in memory.
= 9 Marks) Mark
b. No character translation takes place s
c. Every line ends with a new line character
d. pickle module is used for reading and writing (1)
Page: 3/6
29. Write a Python function that displays all the words containing @cmail
(3)
from a text file "Emails.txt".
Write the function to read the content from the file , display the words which are having the
30. length of exactly 4 characters. (3)

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.

What do you mean by file and write the different (4)


33.
modes of accessing a file available in python

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)

For example, a sample record of the file may be: (4)


[‘Signiland’, 5673000, 5000, 3426]

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.

Q.No. SECTION E (2 X 5 = 10 Marks) Mark


s
36. Surya is a manager working in a recruitment agency. He needs to manage the records of
various candidates. For this, he wants the following information of each candidate to be
stored:
- Candidate_ID – integer
- Candidate_Name – string
- Designation – string
- Experience – float (5)

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

import ___________ # Statement-1


def AddItem(Item, Price) ___ # Statement-2
f=open(“STORE.CSV”, ___ ) # Statement-3
fw=csv.writer(f)
fw.writerow([Item, Price])
____________ # Statement-4

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

Q1. Which module should be imported in Statement-1.


A. pickle B. csv C. file D. text
(5)
Q2. Which file mode to be passed to add new record in Statement-3.
A. w+ B. w C. wb D. a
Q3. What should be written in Statement-4 to close the file?
A. close() B. fw.close() C. f.close() D. csv.close()
Q4. Which function to be used in Statement-5 to read the data from a csv file.
A. read() B. readline() C. readlines() D. reader()
Q5. Output after executing Statement-6 will be -
A. (“Sugar”, “38.0”) B. Sugar 38.0
(“Rice”, “48.50”) Rice 48.0

C. Sugar, 38.0 D. Sugar # 38.0


Rice, 48.50 Rice # 48.50

Page: 6/6

You might also like