0% found this document useful (0 votes)
29 views3 pages

Worksheet Data File Handling

This document is a worksheet for a Computer Science class at Shriram Global School, focusing on data file handling in Python. It contains a series of questions related to file operations, including reading, writing, and manipulating data in text and binary files. Additionally, it includes programming tasks that require writing functions to manage candidate and employee records, project details, and product information.

Uploaded by

Aayushi Mishra
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)
29 views3 pages

Worksheet Data File Handling

This document is a worksheet for a Computer Science class at Shriram Global School, focusing on data file handling in Python. It contains a series of questions related to file operations, including reading, writing, and manipulating data in text and binary files. Additionally, it includes programming tasks that require writing functions to manage candidate and employee records, project details, and product information.

Uploaded by

Aayushi Mishra
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/ 3

SHRIRAM GLOBAL SCHOOL, WHITEFIELD, BLR-67

COMPUTER SCIENCE
WORKSHEET – DATA FILE HANDLING

QN. NO QUESTION
1 Which of the following is the correct usage for tell() of a file object………………….?
a) It places the file pointer at the desired offset in a file.
b) It returns the byte position of the file pointer as an integer.
c) It returns the entire content of the file.
d) It tells the details about the file.
2 Which of the following option is the correct python statement to read and display the first 10
characters of a text file “Notes.txt”?
(a) F=open(‘Notes.txt’) (b) F=open(‘Notes.txt’)
print(F.load(10)) print(F.dump(10))

(c) F=open(‘Notes.txt’) (d) F=open(‘Notes.txt’)


print(F.read(10)) print(F.write(10))
3 Which Python approach is used for object serialization in handling of Binary File?
(a) Pickling (b) Un-pickling (c) Merging (d) None of these
4 Write the missing statement to complete the following code:
file = open("abc.txt", "r")
d = file.read(50)
____________________ #Move the file pointer to the beginning of the file
next_data = file.read(75)
file.close()
5 Which of the following File Open modes opens the file in append and read mode. If the file
doesn’t exist, then it will create a new file.
a. “a+” b. “r+” c. “a+r” d. “r+a”
6 Write a Python function that displays all the words starting from the letter ‘C’ in the text file
"chars.txt".
7 Write a function that displays the line number along with no of words in it from the file
Quotes.txt
Example :
None can destroy iron, but its own rust can!
Likewise, none can destroy a person, but their own mindset can
The only way to win is not be afraid of losing.
Output:
Line Number No of words
Line 1: 9
Line 2: 11
Line 3: 11
8 Write a Python function that extracts and displays all the words containing a hyphen ("-")
from a text file "HyphenatedWords.txt", which has a three letter word before hypen and four
letter word after hypen.
For example: “for-them” is such a word.
9 Write a method/function show_todo():in python to read contents from a text file abc.txt and
display those lines which have occurrence of the word “ TO” or “DO”
For example:
If the content of the file is
“THIS IS IMPORTANT TO NOTE THAT SUCCESS IS THE RESULT OF HARD WORK.
WE ALL ARE EXPECTED TO DO HARD WORK.
AFTER ALL EXPERIENCE COMES FROM HARDWORK.”

The method/function should display:


THIS IS IMPORTANT TO NOTE THAT SUCCESS IS THE RESULT OF HARD WORK.
WE ALL ARE EXPECTED TO DO HARD WORK.
10 i. What is Binary File?
ii. Consider a binary file stock.dat that has the following data: OrderId,
MedicineName,Qty and Price of all the medicines of wellness medicos, write the following
functions:
a) AddOrder() that can input all medicine orders.
b) DisplayPrice() to display details of all medicine that have Price more than 500
11 Amit 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
You, as a programmer of the company, have been assigned to do this job for Amit.
(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 12 years
and change their designation to "Sr. Manager".
(iii) Write a function to read the data from the binary file and display the data of all those
candidates who are not "Sr. Manager".
12 Raj is a supervisor at a software development company. He needs to manage the records of
various employees. For this, he wants the following information of each employee to be
stored:
Employee_ID – integer
Employee_Name – string
Position – string
Salary – float
You, as a programmer of the company, have been assigned to do this job for Raj.
(I) Write a function to input the data of an employee and append it to a binary file.
(II) Write a function to update the data of employees whose salary is greater than 50000 and
change their position to "Team Lead".
(III) Write a function to read the data from the binary file and display the data of all those
employees who are not "Team Lead".
13 Ms Joshika is the Lab Attendant of the school. She is asked to maintain the project
details of the project synopsis submitted by students for upcoming Board Exams.
The information required are:
-prj_id - integer
-prj_name-string
-members-integer
-duration-integer (no of months)
As a programmer of the school u have been asked to do this job for Joshika and define
the following functions.
i) Prj_input() - to input data of a project of student and append to the binary
file named Projects
ii) Prj_update () - to update the project details whose member are more than 3 duration as 3
months.
iii) Prj_solo () - to read the data from the binary file and display the data of all project
synopsis whose member is one.
14 (i) What are the similarities and difference between a+ and w+ file modes in Python.
(ii) A binary file “product.dat” has structure [PNO, PNAME, BRAND_NAME, PRICE] to
maintain and manipulate Product details.
 Write a user defined function CreateFile() to input data for a record and add to
“product.dat” file. The number of records to be entered until the user chooses ‘Y’ /
‘Yes’.
 Write a function CountData(BRAND_NAME) in Python which accepts the brand
name as parameter and count and return number of products by the given brand are
stored in the binary file “product.dat”.

************************************************

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