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

Xii Cs Worksheet-csv File

The document outlines various Python programming exercises focused on handling CSV files, including functions for adding, reading, and displaying customer, inventory, student, animal, employee, furniture, plant, patient, user login, book, movie, teacher, and winner records. Each exercise specifies the structure of the data to be stored and the operations to be performed. Additionally, it includes tasks for counting records and searching based on specific criteria.

Uploaded by

Mohammed Mishal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Xii Cs Worksheet-csv File

The document outlines various Python programming exercises focused on handling CSV files, including functions for adding, reading, and displaying customer, inventory, student, animal, employee, furniture, plant, patient, user login, book, movie, teacher, and winner records. Each exercise specifies the structure of the data to be stored and the operations to be performed. Additionally, it includes tasks for counting records and searching based on specific criteria.

Uploaded by

Mohammed Mishal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

BHARATHI VIDHYALAYA SENIOR SECONDARY SCHOOL

WORK SHEET – CSV FILE HANDLING


CLASS: XII SUBJECT: COMPUTER SCIENCE
1 Write a program using two functions :
(a) addCustomer( ): To write Customer code, Customer name and Amt in file “cust.csv”.
The details of the customers are as follows :
[‘CustCode’, ‘CustName’, ‘Amount’]
[‘001’, ‘Nihir’, ‘8000’]
[‘104’, ‘Akshay’, ‘5000’]
(b) readCustomer( ): To read the details of the customers and display them.
2 Write a program using following functions :
(a) getlnventory() : Write code to accept as many inventory records and store them to the csv file Inventory.csv
storing records of inventory as per following structure PCode, Invname, Price, Reorder.
(b) Display() : To display the detail that store in Inventory.csv
3 Write a program to write into a CSV file “one.csv” Rollno, Name and Marks separated by comma. It should
have header row and then take input from the user for all following rows. The format of the file should be as
shown if user enters 2 records.
Roll.No,Name,Marks
20,Ronit,67
56,Nihir,69
Write a program to read all content of “student.csv” and display records of only those students who scored
more than 80 marks. Records stored in students is in format : [Rollno, Name, Marks]
Write a program in Python that defines and calls the following user defined functions:
i. Add(): to add the record of a student to a csv file “record.csv”. Each record should be with field elements
[admno,sname,class]
ii. Count(): to count the number of students studying in class 12
Write a program in Python that defines and calls the following user defined functions:
i. Add(): to add the record of an animal to a csv file “animal.csv”. Each record should be with field elements
[animalname, animaltype, animalfood]
ii. Search(): to print all the animal names who eat grass as their food.
Write a Program in Python that defines and calls the following user defined functions:
(i) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a list
with field elements as empid, name and mobile to store employee id, employee name and employee
salary respectively.
(ii) COUNTR() – To count the number of records present in the CSV file named ‘record.csv’.
Give any one point of difference between a binary file and a csv file. Write a Program in Python that defines
and calls the following user defined functions:
(i) add() – To accept and add data of an employee to a CSV file ‘furdata.csv’. Each record consists of a list
with field elements as fid, fname and fprice to store furniture id, furniture name and furniture price
respectively.
search()- To display the records of the furniture whose price is more than 10000.
Write a Program in Python that defines and calls the following user defined functions:
A csv file "PLANTS.csv" has structure [ID, NAME, PRICE].
- to input data for records from the user and write them to the file PLANTS.csv. Each
record consists of a list with field elements as ID, NAME and PRICE to store plant id, plant name and price
respectively
- To read the records of PLANTS.csv and displays those records for which the PRICE is
more than 500.
A csv file "PATIENTS.csv" has structure [PID, NAME, DISEASE].
Write the definition of a function countrec()in Python that would read contents
of the file "PATIENTS.csv" and display the details of those patients who have
the DISEASE as 'COVID-19'. The function should also display the total number
of such patients whose DISEASE is 'COVID-19'.
Write a program in python that defines and calls the following user defined functions:
(I) addCsvFile(UserName,Password) – To accept and add the login details of a user into the CSV file
‘login.csv’. Each record consist of a list with field elements as [id,pass] to store Username and password
respectively.
(II) checkDetails(username,pass) – To check the login details passed to the finction from the file. If the
details are correct the function returns True otherwise it returns False.
Write a program in python that defines and calls the following user defined functions:
(i) insertData() – To accept and add data of a customer and add it to a csv file ‘customerData.csv’. Each
record should contain a list consisting customername,mobileno,dateofPurchase,itempurchased.
(ii) frequency (name) – To accept the name of a customer and search how many times the customer has
purchased any item. The count and return the number.
Write a program in Python that defines and calls the following user defined functions:-
(a) AddUser() – to accept and the username and password to a CSV file “Users.CSV”. Each record consists
of a list with field elements as UID and PWD to store User ID and Password respectively.
(b) Search() – To search and display the password of the given User ID.
Write a program in Python that defines and calls the following user defined functions:
WriteCSV() – to accept RollNo, Name and Marks of a student from the user and Write it to CSV file.
ReadCSV() – To read the contents from the CSV file and display it to the user.
Write a Program in Python that defines and calls the following user defined functions:
Add_Book():
To accept data of new book and add to ‘library.csv’ file. The record of book consists book_id, book_name
and book_price in form of python list.
Show_Book():
To read the records of books from ‘library.csv’ file and display the record of books which price is more than
Rs. 500.
A CSV file “Movie.csv” contains data of movie details. Each record of the file contains the following data:
1.Movie id
2.Movie name
3.Genere
4.Language
5.Released date
For example, a sample record of the file may be:
["tt0050083",’ ‘12 Angry Men is’,’Thriller’.’Hindi’,’12/04/1957’]
Write the following functions to perform the specified operations on this file

(i) Read all the data from the file in the form of the list and display all those records for which language is in
Hindi.
(ii) Count the number of records in the file.
Write a Program in Python that defines and calls the following user defined functions:
(i) ADD() – To accept and add data of a teacher to a CSV file ‘teacher.csv’. Each
record consists of a list with field elements as tid, name and mobile to
storeteacherid,teacher name and teacher mobile number respectively.
(ii) COUNTRECORD() – To count the number of records present in the CSV file
named
‘teacher.csv’.
A CSV file named ‘Winner_details.csv’ contains the following information:-
• Winner name
• Event name
• Points scored
• Position secured

For example, a sample record of the file may be:-


['Medusa George','Hackathon',45,3]
Write the following Python functions to perform the specified operations on this file:
i Read all the data from the file in the form of list and display average points scored by all winners
who have secured 3rd position.
ii Insert a new record into the file.
Write a Program in Python that defines and calls the following user defined functions :
(a) add( ): To accept and add data of an employee to a CSV file 'furdata.csv'. Each record consists of a list
with field elements as fid, fname and fprice to store furniture id, furniture name and furniture price
respectively.
(b) search( ): To display the records of the furniture whose price is more than 10000.
A CSV file ‘empdata.csv’ consists of a list with field elements as Eid, Ename, Salary and City to store employee
id , employee name, employee salary and city. Write a Program in Python that defines and calls the following
user defined functions:
SEARCH()- To display the records of the employees whose salary is more than 25000.
COUNTROW() – To count the number of records present in the CSV file named ‘empdata.csv’.

You might also like