0% found this document useful (0 votes)
25 views

12PythonAssign TextFile2

The document describes Python assignments involving working with comma separated text files (.txt) and comma separated value files (.csv). The assignments include creating, reading, appending, updating, searching and filtering data in the text and csv files. Functions are to be written to perform tasks like adding/reading records, searching by code/item/director, updating records by modifying fields, filtering by criteria etc. on the product, teacher and play data stored in the text and csv files.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

12PythonAssign TextFile2

The document describes Python assignments involving working with comma separated text files (.txt) and comma separated value files (.csv). The assignments include creating, reading, appending, updating, searching and filtering data in the text and csv files. Functions are to be written to perform tasks like adding/reading records, searching by code/item/director, updating records by modifying fields, filtering by criteria etc. on the product, teacher and play data stored in the text and csv files.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Assignments #2 Class XII Comma Separated Text File

1. A comma separated text file PRODUCT.TXT is to be created with following components:


code int type (4 digits – item code)
item str type (item details)
qty int type (quantity)
price float type (item price)
a) Write Python function to append n (local variable) records (lines) in the text file. At the end display
number records (lines) present in the text file.
b) Write a Python function to read the text file and display the text file on the screen. At the end
display number records (lines) present in the text file.
c) Write a Python function to input code and search for the code in the text file. If the code is located
in the text file then display code, item, qty and price on the screen. If the code could not be
located in the text file then display an error message 'Code not found in the file'.
d) Write a Python function to input item and search for the item in the text file. If the item is located
in the text file then display code, item, qty and price on the screen. If the item could not be located
in the text file then display an error message 'Item not found in the file'.
e) Write a Python function to read the text file and display code, item, qty and price on the screen
when qty>20. If no such record (line) found in the text file then then display an error message
'Record not found in the file'.
f) Write a Python function to read the text file and display code, item, qty and price on the screen
when qty>=20 and qty<=50. If no such record (line) found in the text file then then display an
error message 'Record not found in the file'.
g) Write a Python function to read the text file and display code, item, qty and price on the screen
when price<50. If no such record (line) found in the text file then then display an error message
'Record not found in the file'.
h) Write a Python function to read the text file and display code, item, qty and price on the screen
when price>=100 and price<=200. If no such record (line) found in the text file then then display
an error message 'Record not found in the file'.
i) Write a Python function to read the text file and display code, item, qty and price on the screen
when price>=100 and qty<50. If no such record (line) found in the text file then then display an
error message 'Record not found in the file'.

2. A CSV file PRODUCT.CSV is to be created with following components:


code int type (4 digits - item code)
item str type (item details)
qty int type (quantity)
price float type (item price)
a) Write a Python function to create the CSV file by adding (appending) n number of records in the
file. Variable n is local to the function.
b) Write a Python function to read the CSV file and display the CSV file on the screen. At the end
display number records present in the CSV file.
c) Write a Python function to update all the records (line) in the CSV file by decreasing price of
every item by 20%.
d) Write a Python function to update all the records (line) in the CSV file by increasing qty of every
item by 100
e) Write a Python function to input code. Locate the code in the CSV file and update the record (line)
in the CSV file by increasing price (add 10 to the existing price). If the code could not be located
in the CSV file then display an error message 'Code not found in the file'.
Page 1 of 2
Python Assignments #2 Class XII Comma Separated Text File
f) Write a Python function to input code. Locate the code in the CSV file and update the record (line)
in the CSV file by decreasing qty (deduct 20 from the existing qty). If the code could not be
located in the CSV file then display an error message 'Code not found in the file'.
g) Write a Python function to input code. Locate the code in the CSV file and delete that record (line)
from the CSV file. If the code could not be located in the CSV file then display an error message
'Code not found in the file'.
h) Write a Python function to input item. Locate the item in the CSV file and delete that record (line)
from the CSV file. If the item could not be located in the CSV file then display an error message
'Item not found in the file'.

3. A CSV file TEACHER.CSV exists with following components:


code int type (4 digits – teacher code)
name str type (name of the teacher)
subject str type (subject of the teacher)
desig str type (designation - HOD/PGT/TGT/PRT)
periods int type (number of periods)
a) Write a Python function to read the CSV file and display details if desig is HOD. At the end
display number of such records (lines) found in the file.
b) Write a Python function to read the CSV file and display details if desig is TGT. At the end display
number of such records (lines) found in the file.
c) Write a Python function to read the CSV file and display details if desig is PGT and subject is
either PHYSICS or CHEMISTRY. If no record (line) found in the CSV file then display an error
message 'Record not found in the file'.
d) Write a Python function to read the CSV file and display details of teachers whose desig is either
TGT’s or PGT’s and subject is ENGLISH. If no record is found then display an error message
'Record not found in the file'.
e) Write a Python function to read the CSV file and display details if periods<28 and desig is PRT.
If no record (line) found in the CSV file then display an error message 'Record not found in the
file.'
f) Write a Python function to read the CSV file and display details if desig is either PRT or TGT. If
no record (line) found in the CSV file then display an error message 'Record no found in the file'.
g) Write a Python function to read the CSV file and copy all the records (lines) from the CSV file
into another CSV file HODPGT.CSV if desig of the teacher is either HOD or PGT.

4. A CSV file PLAY.CSV exists with following components:


title str type (title of the play)
director str type (name of the director of the play)
duration int type (duration in minutes)
a) Write a Python function to append n (n parameter to the function) records (lines) in the CSV file.
b) Write a Python function read the CSV file and display the CSV file. At end display number of
records when duration is less than 120.
c) Write a function in Python to read the CSV file and display details of the plays if duration>150.
d) Write a function in Python to input director and search for the director in the CSV file. If the
inputted director is located in the CSV file then display title, director and duration on the screen.
If the director could not be located in the CSV file then display an error message 'Record not
found in the file'.

Page 2 of 2

You might also like