0% found this document useful (0 votes)
117 views2 pages

File Handling 2

The document outlines homework assignments for programming tasks in Python, including reading and processing text and binary files, managing CSV files for student and employee records, and performing specific data manipulations such as counting words and editing records. Key tasks involve creating functions to filter and display data based on given criteria, such as expensive products and employee details. The assignments emphasize file handling, data structures, and user-defined functions.

Uploaded by

Geetha Ponraj
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)
117 views2 pages

File Handling 2

The document outlines homework assignments for programming tasks in Python, including reading and processing text and binary files, managing CSV files for student and employee records, and performing specific data manipulations such as counting words and editing records. Key tasks involve creating functions to filter and display data based on given criteria, such as expensive products and employee details. The assignments emphasize file handling, data structures, and user-defined functions.

Uploaded by

Geetha Ponraj
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/ 2

Home work : 16/7/2024

1. A text file contains alphanumeric text (say an.txt).Write a program that reads this text file and
prints only the numbers or digits from the file.
2. Consider a binary file 'INVENTORY.DAT' that stores information about products using tuple
with the structure (ProductID,ProductName, Quantity, Price).
Write a Python function
expensiveProducts() to read the contents of 'INVENTORY.DAT' and display details of
products with a price higher than Rs. 1000. Additionally, calculate and display the total count
of such expensive products.
For example: If the file stores the following data in binary format
(1, 'ABC', 100, 5000)
(2, 'DEF', 250, 1000)
(3, 'GHI', 300, 2000)
then the function should display
Product ID: 1
Product ID: 3
Total expensive products: 2

3. Write a Program in Python that defines and calls the following user defined functions:
(i) insert_ROLL()– To accept and add data of a student to a CSV file ‘marks.csv’.
Each record consists of a list with field elements as rollno, mark to store roll number
and mark of students respectively.
(ii) read_ROLL()- To display and count the records of the students.
(iii) Create a function maxsalary() in Python to read all the records from an already existing
file record.csv which stores the records of various employees working in a department. Data
is stored under various fields as shown below:
E_code E_name Scale Salary
A01 Bijesh Mehra S4 65400
B02 Vikram Goel S3 60000
C09 Suraj Mehta S2 45300
…… …… …… ……
Function should display the row where the salary is maximum.
Note: Assume that all employees have distinct salary
4. Write a python program that define the following user defined function:
1. add(): add the teacher details [tid,name,designation salary department] into the csv file
teacher.csv
2. count_teacher(dept): accept department as argument and display number of employess in
that department.
Home work : 17/7/2024
1. Write a function in python to count number of words ending with ‘n’present in a
text file “ABC.txt”
If ABC.txt contains “A story of a rich man And his son”, the output of thefunction
should be
Count of words ending with ‘n’ is 2
2. Following is the structure of each record in a data file named "phonebook.DAT".
{“name”: value, "phone": value}
Write a program to edit the phone number of “Arvind” in file “phonebook.dat”. If there is no
record for “Arvind”, report error.
3. Write a prigram in python that defines the following user defined functions:
• add_emp() To add the employee details into csv file which contain the information of
[emp_id,emp_name,desingation,salary,place]
• display-emp() display the details of employee whose designation is manager and salary
is greater the 60000
• count_designation(desig): accept the parameter value for desig and display the number
of employee work as a particular designation.
• read_emp(): display the details of the employee whose name start with ‘a’ and his place
is “chennai”
• count_emp(place): accept the parameter for place and display the details of the
employee from that place and also display the number of employees from that place.If
there is no employees from that place display appropriate message

You might also like