Python programs for practical exam
Python programs for practical exam
Task Marks
Write a Python program with the following user defined functions:
• Function to write those lines which have the character 't' from one text
file “Source.txt” to another text file called “Destination.txt”.
1 8
(Create the “Source.txt” in Notepad and write data to the file using notepad editor)
• Function to count and print the total number of vowels in the file “Source.txt”
Write a program to add the following header in a csv file ['COUNTRY', 'CAPITAL', 'CODE']
called “countries.csv”. Write a function to accept data from the user and write to the file till
3 the user wishes to continue. 8
Write a function to display the details from the csv file “countries.csv”
A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price].
a) Write a user defined function CreateFile( ) which will accept data for a record from the
user and add details to Book.dat .
4 8
b) Write a function CountRec(Author) in Python which accepts the Author name as
parameter. The function counts and returns the number of books by the given Author
stored in the binary file “Book.dat
5 Write a program to perform the operations (push, pop and display) on a stack of integers in 8
python. LIST PROGRAM
The “Products.csv” file has the following header ['PID','PNAME','COST', ‘QUANTITY’].
6 Write a function to add the records in the “Products.csv” file. 8
Write a function to display the total quantity of all the products in the csv file.
Write a Python program that creates a binary file containing the student’s roll number, name
and percentage.
7 The insert function (user defined function) should accept values from the user and write the 8
information (list) in the binary file.
The display function should print all the records from the binary file.
Page 1