Test Data File Handling

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Data File Handling

SET - A
Q1. Write a function in Python that displays the book names having 'Y' or 'y' in their name from a text file
"Bookname.txt".
Example :
If the file 'Bookname.txt' contains the names of following books :
One Hundred Years of Solitude
The Diary of a Young Girl
On the Road
After execution, the output will be :
One Hundred Years of Solitude
The Diary of a Young Girl

Q2. Atharva is a programmer, who has recently been given a task to write a Python code to perform the
following binary file operation with the help of a user defined function/module :
Copy_new() : to create a binary file new items . dat and write all the item details stored in the binary file,
items .dat, except for the item whose item_id is 101. The data is stored in the following
format :
{item_id: [item_name,amount] }

Data File Handling


SET - B

Q1. Write a function RevString() to read a textfile "Input.txt" and prints the words starting with 'O' in reverse
order. The rest of the content is displayed normally.
Example :
If content in the text file is :
UBUNTU IS AN OPEN SOURCE OPERATING SYSTEM
Output will be :
UBUNTU IS AN NEPO SOURCE GNITAREPO SYSTEM
(words 'OPEN' and 'OPERATING' are displayed in reverse order)

Q2. Shreyas is a programmer, who has recently been given a task to write a user defined function named write
bin ( ) to create a binary file called Cust file . dat containing customer information — customer number price
(price) and amount
(c no), name (c name), quantity (qty), ( amt) of each customer.
The function accepts customer number, name, quantity and price. Thereafter, it displays the message 'Quantity
less than 10 Cannot SAVE', if quantity entered is less than 10. Otherwise the function calculates amount as
price quantity and then writes the record in the form of a list into the binary file.

You might also like