Unit Test - 1 Feb 26
Unit Test - 1 Feb 26
1. State True/False.
An absolute path always begins with a root folder.
2. Which of the following method is used to serialize the
Python objects?
a) load b) dump c) write d) writerow
3. Read the code given below and find which of the following
is the content of the file, if the file contains ‘GOOD’
before execution?
With open(‘main.txt’,’w’) as File:
File.write(‘BYE’)
File=open(‘test.txt’,’w+’)
File.write(‘0123456789abcdef’)
File.seek(13) #statement 1
Print(File.read(3)) #statement 2
File.close()
File=open(‘Mydata’,’a’)
File.______________ #Blank 1
File.close()
SECTION – D 4 X 2 = 8
31.Consider a binary file ‘vehicles.dat’ contains the
records in the following structure.
{‘Vcode’:value,’Vtype’:value, ‘perkm’:value}.
Complete the missing statement in the following python
code to read and copy only the ‘Deluxe’ type of vehicles
into the file ‘Deluxe,dat’.
SECTION – E 3 X 5 = 15
33.A binary file ‘Books.dat’ has the structure
[BookNo, BookName, Author, Price]
Write a user defined function Create_File() to insert a
record and add to “Books.dat”. Also write a function
CountRec(Author) in Python which accepts the author as
parameter and count and returns the number of books
written by the given Author. If no record is found,
display the appropriate message.
34.A) Write a function DISPLAYWORDS() in Python to read
from a text file ‘POEM.TXT’ and display those words
which are less than 4 characters.
B) Write the syntax to open a file using ‘with’ clause.
State its advantages.
35.Following is the structure of each record in a data
file named ‘PRODUCT.DAT’.
{‘prod_code’:value,’prod_desc’:value,’stock’:value}
The values for prod_code and prod_desc are strings and
for stock is an integer.
Write a Python program that defines and calls the
following user defined functions.
A) ADD_DATA() – To add the records into the file
‘PRODUCTS.DAT’ as long as the user wants.
B) UPDATEREC()- To update the file with a new value of
stock. The stock and the prod_code, whose stock is to
be updated, are to be inputted during the execution of
the program.