0% found this document useful (0 votes)
7 views5 pages

Oksnnnjkapoooooo

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

Oksnnnjkapoooooo

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

Multiple Choice Questions (Tick

() thefile?
L 1.Which is irrelevant term for a binary correct answers):
(a)pickle (b) load
2.Whichof the followiving (c) dump
statements
(a)It is machine readable form. is not
in a valid
binary
(d) scratch
file?
(b)Data is stored using ASCII or Unicode characters.
Data is stored in binary form.
above
(d) All of the
3.In whhat way the data is stored in a binary file?
(a) As a
text (b) As integers
(c) As a list
of (d) As a stack
4 Which the following statements is correct for "wb+" mode?
(a) It enables writing and reading operations.
(b) It disables writing but enables reading operations.
(c) It enables reading followed by writing operations.
(a) None of the above
t Which of the following statements true while writing data into a binary
(a) Declaration of a file object file?
(b) Use of open( ) function
(c) Opening a file in write mode (d) All of these
6. What is the use of "ab+" mode in file
(a) append and read
handling?
(b) read and append
(c) append and write (d) append, read and write
7. Which of the following functions is used to write data in a
binary file?
(a) write (b) dump (c) load (d) print
8. Which of the following statements is correct?
(a) insert pickle (b) import pickle_module
(c) import pickle (d) include pickle
9. What is the purpose of tell( ) function in a file?
(a) To set the file pointer at the beginning of a file.
(b) To set the file pointer at the end of a file.
(c) To specify the current location of the file pointer.
(d) To state the number of bytes a file contains.
10. In which of the file mode in a binary file, the existing data will remain intact?
(a) wb (b) wb+ (c) ab (d) w+
I. Fill in the
blanks:
1. The binary files are stored in the computer's memory in terms of
2 a byte stream.
1s a process which converts a Python object into
3. the user.
folder is created automatically when system is made ready for
4 specified fle.
path always begins with the root to reach to the structures.
5 Python object
is a process which is used for serialising Gle.
6. In pickle function is used to write data into a binary
module,of
7. The technique managing error when end of the file has encountered in a program,
is
referred to as
8. The mode Overwrites the file, if the file
new file for writing. exists,
9. A single dot () is used for the
the folder.
folder whereas, twootherwise
10. The <file_object.close( )> returns if
dots (.)
the fille is
I1. State whether the following statements are True or
False:
still opened
1. When a byte stream is converted into an
object, it is
2. In a computer's memory, one character is stored in known as
byte. unpickling,
8-bits pattern to
dictionary elementrepsresent
The binary files don't allow reading and a
writing of
4. The integer numbers are
stored as strings in a binary file
5. There is no
difference between serialisation and pickling.
6. The secondary name of a
binary file is always represented by .dat.
7. The directory which is
currently in use is called parent director.
8. The process of retrieving the
records of a binary file a into
as Deserialisation' Python object
9. The mode 'rb+'
opens a file for both appending and
reading in binary forma
10. In a binary file, the records are
stored as a list.
IV. Assertion and Reason
based questions:
1. Assertion (A): Pickling and unpickling are the usual activities
binary file. while working g.
Reason (R): Pickling is the process to
dictionaries, etc.) into machine readable convert
byte
the input objects (ie, lists, tue
stream
in terms of byte gets stored in the (binary form). The infomatz
binary
Based on the above discussion, choose an file.
given below: appropriate statement from the opn
(a) Both A and R are true and R
is
(b) Both A and R are true and R is the correct explanation of A.
(c) A is true butR is false.
not the correct explanation of A.
(d) A is false but R is true.
(e) Both A and R are false.
2. Assertion (A): The techrnique of
is referred to as managing the error when encountered in the puy
Exception
Reason (R): It is essentiallyHandling.
needed provides
end of records in the file. Python because try-except
the system blocks
does not hnd any thusen
to eliminate
When the try-block experiences EOFError, the except block comes into an at
manage the same. gar
Based on the above discussion, choose an appropriate statement
tromthe
given below:
(a) Both A and R are true and
(b) Both A and R are true and R isis not
the correct explanation of A.
the correct explanation on
(c) A is true but R is false.
(d) A is false but R is true.
(e) Both A and R are false.
3. Assertion (A): The file pointer is used to point a location in the ile from
specific record has to be accessed or
modified.
provides two functions viz. seekl ) and tel )to work with rando
(R) Python
tell ) function is used to change the position of
the file pointer.
Keason
The
hle.
returns the current position of the file pointer.
thesek)function
discussion, choose an appropriate staternent from the options
Mess
Wheeas,
t h e above
On
RIset
given
below: and Ris the correct explanation of A.
and R are true
A and Ris not the correct explanation of A.
and R are true
Both
(a)
Both A is false.
b) true but R
c)A falsebut R is true.
is
is
(d)A and R are false.
Both A
(e) (A); The 'rb+'
mode allows opening a file in read as well as write mode.
write
Asserlion
this mode, the file is read first followed by writing. If you try to
(R): In
4 Reason
before reading, the content will be overwritten.
information
discussion, choose an appropriate statement from the options
the the above
Rased on
givenbelow:
are true
and Ris the correct explanation of A.
Both Aand R
(a) and R are true
and R is not the correct explanation of A.
A
b)Both is false
but R
(c) A is true butR is true.
Id) Ais
false
false
Both A and R are
le)
questions:
based type of file,
Case Study which stores information in machine readable form. With this and other to
Ge
module which includes two methods, one to read data from it implement
ce a
While writing a code to work with such a file, we can
Gte data into it.
exceptions during execution.
ablock which handles answer the following questions:
Rased on the above discussion,file!
of such
(a) What is the name (iü)) Machine coded file
i) Text file
(iv) Program file
(ii) Binary file
is used to work with this file?
(b) Which of the following modules (iiü) random (iv) NumPy
(i) pickle
(i) math file?
is used to store data into this
(c) Which of the following functions (iv) dump( )
(ii) print( (ii) store( )
(i) write()
handling?
(d) Which of the following blocks is used for exception (iv) None of these
(i) try-except (ii) through-except (ii) try-catch
to create a binary file with the name
4 10ur teacher has given an assignment records, each containing Roll,
Kesult.dat" through file handle 'fwb' to write some
Name and Marks in computer science of a student.
Dased on the above information, answer the following questions:
work with this file.
Wnte a statement to include the module required to
b) Writer statement to open the given file.
Name the function which is used to write the records in the given file.
(d) Write astatement to close the given file.
Wite short answers:
1. What is
the significance of a'Binary File'?
2What are the different types of data a binary file can
contain? Name them.
3.What are the limitations of using pickle module?
4. Name the
functions under pickle module to read and write into a binary file.
5. Define the following terms:
(a) Exception handling (b)
6. Explain the meaning of the following file objectUpdating a file
attributee.
(a) fn.name (b) fn.mode
(c) fn.closed
where 'fn' represents the file object.
7. How can you avoid
errors, if encountered while
8. Explain the meaning of the
(a) rb+ (b) ab+
following modes in binary flee: reading records from
9. The seek( ) (c) wb+
function with different
(a) seek(8) (b) sek(3, 0) arguments(c)
are given
seek(6, 1) beloue.
How will the file pointer in
each of the (d) seekl4,2
reference points? above cases will
10. Distinguish between: change
(a) 'wb+' and 'ab+'
modes
with repen
11. What is the (b) Text files and binary iles
application
12. Write down the
of tell( )
function?
(a) to search a steps:
(b) to append a
record in a binary file
record in an existing
binary file
VIL. Unsolved Python
1. Write a Codes on Binary Files
program code to
create a file 'Store.dat'
smartphones (Company Name, Model and the Price) which till thestores
2. Write a the
function def Salary( ) in Python to user wantsdetails
employee'
mode s code, employee's name and create a binary file 'Emplovee at
to retrieve
Emp_Code
each record and
displayemployee' s salary.
its content Open the
in the format fil ee in
Emp_Name Salary shownappopr
bela
3. The class teacher wants to
'Prize Winners' of class XIImake file 'Prize.dat' which
a
all the names
along with students.
the
contains the records of al
Write a function def
Name class and rank as Prize( )in Pvthon to stn
Class shown below:
Rank
4. Write a function def
and Price) from an High_Low() in Python which reads
smartphone existing file named data (Company name, Mis
the highest and the'Phone.dat. Display the particulas a
[Assume thatpossessing
the file is already lowest price.
5. The file
name 'Marks.dat' keeps present in the hard
names and marks the records of all thedisk.]
def Total( secured in English, students of class XII with
function
the names in the ) in Maths,
Python which reads theScience and Computer Science.
format given below: data from the above nle a
Name Eng Maths Science Total
Computer
6. Abinary
file
The company 'Phashone.dat' contains Model and Old price of the various functiond smartphs
decided
Phone_Update( )to retrieve eachto recordtheandphone
enhance displaypricesthe byModel,
20%. OlWrite
d Priace, andNew
Price in the
following format:
Old Price
Model New Price

'Name.dat' oontains the names of the students of class XII. Write a function
Add_name()
ile in Python to add few more names in the file till the user wants.
zA
ibrarianhas created a binary file Library.dat' storing the book's title and class.
function def Search( ) to open the file in appropriate mode to display the
Witea title of only
those books which belong to class 11 and class 12.
s
ok
fleSubject.dat'contains few subject names and class (XI-XII) as dictionary elements
reference to 'key-value' pairs. Write a function def Add_Sub() to add the
with in the existing file.
dictionarygivven
('Axounts"9,"Commerce"":10,"Economics":1,"Mathematics":12)
'Result.dat' is created to store the roll number, name and total marks secured by
fle
1 .Anumber of students.
Open the file in 'rb+' mode and update it with the following
a
intormation:
Hence, delete his/her record.
student with roll number 8 has left the school.
wrongly entered as 549.
(a) A marks of a student whose roll number is 23 is
Thetotal
b) his/her marks to 649
Change
studenthas joined the school. Hence, add his/her
record with the following
new
A
(c)informaton:
number : 45
Roll : Sumit Prakash
Name
489
Total

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy