Report File Xii Lab Programs 13 To 18

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

EX.

NO:13 WORKING WITH BINARY FILE IN PYTHON


Create a binary file, Search and display the records from the binary file
AIM:
(i) To write a user defined function CreateFile() to input the records and add to the binary file
‘Books.dat’ which has the structure [Book_ID, Book_Name, Author, Price].
(ii) To write a function CountRec(Author) which accepts the Author name as parameter and display
the book names and return number of books by the given Author stored in the binary file
‘Books.dat’.
SOURCE CODE:

RESULT:
Thus the user defined functions to create a binary file ‘Books.dat’ and to search and display the book
names number of books by the given Author has been developed in Python and executed
successfully.
EX.NO:14 WORKING WITH BINARY FILE IN PYTHON
Create a binary file, Update and display the records from the binary file
AIM:
(i) To write a user defined function AddData() to input and add the records to the binary file
‘Employee.dat’ which has the structure { ‘EmpCode’: _______, ‘EmpName’:_________,
‘Designation’:_______,’Salary’:________ }.
(ii) To write a function UpdateRec(Desgn) which accepts the designation as parameter and update the
salary for the employees with the given designation in the file ‘Employee.dat’. Also display the
records from the file.
SOURCE CODE:
RESULT:
Thus the user defined functions to add records to a binary file ‘Employee.dat’ and to update the salary
and display the records in the file has been developed in Python and executed successfully.

EX.NO:15 WORKING WITH BINARY FILE IN PYTHON


Create a binary file, Delete and display the records from the binary file
AIM:
To write a Menu driven Python program to implement the following user defined functions.
(i) Create() to input and add the records to the binary file ‘Products.dat’ which has the structure
[ProdID,ProductName, Quantity, Cost].
(ii) DeleteRec(code) which accepts the product ID as parameter and remove the product with the
given code from the file ‘Products.dat’. Also display the records from the file.
SOURCE CODE:
RESULT:
Thus the menu driven python program with separate user defined functions to add records to a binary
file ‘Products.dat’ and to delete and display the records in the file has been developed in Python and
executed successfully.
EX.NO:16 WORKING WITH CSV FILE IN PYTHON
Create a CSV file, Search and display the records from the CSV file
AIM:
(i) To write a user defined function Create() to input and add the records to the csv file ‘Students.csv’
which has the structure [RollNo, Name, Marks].
(ii) To write a user defined function SearchRec(code) which reads and displays the student records
who have secured above 80 from the file ‘Students.csv’. Also display the number of student records
scored above 80 from the file.
SOURCE CODE:

RESULT:
Thus the user defined functions to add records to a csv file ‘Students.csv’ and to search and display
the records in the file has been developed in Python and executed successfully.
EX.NO:17 WORKING WITH CSV FILE IN PYTHON
Create a CSV file, Update and display the records from the CSV file

AIM:
To write a Menu driven Python program to implement the following user defined functions.
(i) Create() to input and add the records to the csv file ‘Customers.csv’ which has the structure
[Cust_ID,Cust_Name,City, Contact_No]
(ii) UpdateRec(code) to update the contact number of the customer for the code given by the user
(iii) Display the records stored in the file Customers.csv

SOURCE CODE:
RESULT:
Thus the menu driven python program with separate user defined functions to add records to a csv file
‘Customers.csv’ and to update and display the records in the file has been developed in Python and
executed successfully.
EX.NO:18 IMPLEMENTATION OF STACK USING LIST IN PYTHON

AIM:
Consider a dictionary containing non fiction book names and their ratings as key value pairs
as below.
Books={"Behind the beautiful forevers":8.5,"Omnivore's Dilemma":7,"Unnatural
Selection":6.5,"Guns, Germs and Steel":9,"Business Adventures":7.5,"The power of Full
engagement":9.5}
To write a python program with separate user defined functions to perform the following
operations.
(i) Push the keys (Book name) of the dictionary into the stack, where the corresponding value
(rating) is more than 8.
(ii) Pop and display the content of the stack.

Source Code:
RESULT:
Thus the python program with separate user defined functions to implement the stack using list has
been developed in Python and executed successfully.

You might also like