1. Write the difference between absolute path and relative path.
2. What is the advantage of opening a file using with block.
3. Write a program to read following details of sports performance (sport,
competition, prizes-won) of your school and store into a csv file delimied with
tab character.
4. Write a program using Dictionary to store first 10 roman numbers in a binary file
and find their equivalent.
5. What is CSV file? What are its charecteristics?
6. Write about tell() and seek() with example.
7. Write the difference between wirterow() and writerows() in CSV file
8. Differentiate between text file and binary file.
9. Write a function in python to count the number of uppercase alphabets present in the
text file“CLASS.TXT”.
10. Write a function in Python to read a text file, INDIA.txt and displays those lines which
begin with the word „India‟.
11. Write a method COUNTLINES() in Python to read lines from text file
„TESTFILE.TXT‟ and display the lines which are not starting with any vowel.
Example:
If the file content is as follows:
An apple a day keeps the doctor away.
We all pray for everyone‟s safety.
A marked difference will come in our country.
The COUNTLINES() function should display the output as:
The number of lines not starting with any vowel – 1
12. Write a function revtext() to read a text file “story.txt” and print only word starting
with “I” in reverse order.
Example: If value in text file is : “India is my country”
Output will be : “aidnI si my country”
13. Write a function AMCount() in Python, which should read each character of a text file
STORY.TXT, should count and display the occurance of alphabets A and M
(including small cases a and m too).
Example: If the file content is as follows:
Updated information
As simplified by official websites.
The EUCount() function should display the output as:
A or a:4
M or m :2
14. Write a method/function DISPLAYWORDS() in python to read lines from a text file
STORY.TXT, and display those words, which are less than 4 characters.
15. i) Write the difference between append and write access modes.
ii) A binary file named “TEST.DAT” has some records of the structure
[Testid, Subject, Maxmarks, Scoredmarks]
Write a function in python named Displayavgmarks(sub) that will accept subject as
an argument and read the contents of TEST. DAT. The function will calculate and
display the average of the scored marks of the subject which is passed as an
argument.
16. Given a binary file “emp.dat” has structure
{“EMP” : [eid, ename, salary]}
Write a function countsal() in python that would read contents of the file “emp.dat”
and display the details of those employees whose salary is greater than 2000.
17. i) What is delimiter in CSV file.
ii) Write a function copycochin() in python to copy the details of the buses whose
destination is “Cochin” from the file “bus.dat” to the file “cochin.dat”
The file “bus.dat” has the following structure:
[bno, startpoint, endpoint]
18. Write a function routechange(routenumber) which takes the route number as
parameter and modify the route name (accept it from user) of passed route number in
the binary file “route.dat”.
The file has the structure : [routenumber, routename]
19. i) Write about the module pickle.
ii) A binary file “STUDENT.DAT” has the structure
{“Student” : [admission_number, Name, Percentage]}
Write a function countrec() in python that would read contents of the file
“STUDENT.DAT” and display the details of the students whose percentage is
above 75 percentage.
20. Write a function countrec(author) in python which accepts the author name as
parameter and count and return number of books by the given author are stored in
the binary file “books.dat”.
The file “books.dat” has the following structure:
[bookno, book_name,author,price]
21. Write the following user defined functions:
i) add() : To accept a new record from the user and add to the file “stock.csv”. The
column headings should also be added on the top of the csv file.
ii) search() : To display the details of the products whose company is “ Britania”
The file “stock.csv” has the following structure :
[productid, product_name, company, price]
22. Radha Shah is a programmer, who has recently been given a task to write a python
code to perform the following CSV file operations with the help of two user defined
functions/modules:
i) CSVOpen() : to create a CSV file called BOOKS.CSV in append mode
containing information of books – [Title, Author , Price]
ii) CSVRead() : to display the records from the CSV file called BOOKS.CSV
where the book title starts with 'R'.
23. Write a Program in Python that defines and calls the following user defined functions:
A csv file "PLANTS.csv" has structure [ID, NAME, PRICE].
i. WRITEREC() - 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
ii. SHOWHIGH() - To read the records of PLANTS.csv and displays those records
for which the PRICE is more than 500.
24. A CSV “Toy.csv” has structure [TID, Toy, Status, MRP].
i. Write a user defined function CreateFile() to input data for a record and add to
Toy.csv.
ii. Write a function OnOffer() in Python to display the detail of those Toys, which
has status as “ON OFFER” from Toy.csv file.
25. Vijay has created a CSV file „FOOTBALL.CSV‟ to store player name,matches and
goals scored. Write a program in python that defines and calls following user defined
functions.
i) addPlayer(name,matches,goals): Three parameters – name of the player, matches
played and goals scored are passed to the function. The function should create a
list object and append it to the CSV file.
ii) HighestAverage( ): The function should read the CSV file and display the name
of the player with the highest average goals(goals/matches).
26. i. Write a function in Python, Push(book) where, book is a list containing the
details of a book in form of [bookno ,author, price].
The function should push the book number and author of the book which have
price greater than 300 into the stack named “bkdetails”. Also display the count of
elements pushed into the stack.
ii. Write a function POP() to pop the objects from the stack and displays them. Also,
the function should display “Stack Empty” when there are no elements in the
stack.
For example: If the list contains the following data:
book=[[“Python”, “Arora”,350],[“Hindi”, “ Agarwal”,200] ,
[“English”, “Bernard”,270], [“Physics”, “Arora”,600],
[“Chemistry”, “ Chopra”,550]]
The Output must be:
Count of elements pushed in the stack : 3
[“Chemistry”, “ Chopra”]
[“Physics”, “Arora”]
[“Python”, “Arora”]
Stack Empty
27. Vedika has created a list containing names and marks of 5 students. Write a program,
with separate user-defined functions to perform the following operations:
i) push(lst): To push the name of the students who has scored more than 70
ii) pop() : To pop and display the content of the stack. Also, the function should
display “Stack Empty” when there are no elements in the stack.
For Example: The list has
lst=[[“Ramesh”,58], [ “Umesh”,78], [ “Vishal”,90], [ “Khushi”,60], [ “Ishika”,95]]
The output must be: Umesh, Vishal , Ishika
28. Write a function in Python, Push(book) where, book is a dictionary containing the
details of a book in form of {bookno : price}.
The function should push the book in the stack which have price greater than 300. Also
display the count of elements pushed into the stack.
For example: If the dictionary contains the following data:
Dbook={"Python":350,"Hindi":200,"English":270,"Physics":600,
“Chemistry”:550}
The stack should contain
Chemistry
Physics
Python
The output should be:
The count of elements in the stack is 3
29. Write the definition of a user defined function PushNV(N) which accepts a list of
strings in the parameters N and pushes all strings which have no vowels present in it,
into a list named NoVowel.
Write a program in python to input 5 words and push them one by one into a list named
All. The program should then use the function PushNV() to create a stack of words in
the list NoVowel so that it stores only those words which do not have any vowels in it,
from the list All.
Thereafter , pop each word from the list NoVowel and display the message
“EmptyStack”
For example:
If the words accepted and pushed into the list All are
[„DRY‟,‟LIKE‟,‟RHYTHM‟,‟WORK‟,‟GYM‟]
Then the stack NoVowel should store
[„DRY‟,‟RHYTHM‟,‟GYM‟]
And the output should be displayed as
GYM
RHYTHM
DRY
EmptyStack
30.
31.
32. A dictionary stu contains rollno and marks of students. Two empty list stack_roll and
stack_mark will be used as stack. Two functions push_stu() and pop_stu() is defined
and performs the following operation
(a) Push_stu(stu) :- It reads dictionary stu and add keys into stack_roll and values
into stack_marks for all students who secured more than 60 marks.
(b) Pop_stu() :- It removes last rollno and marks from both list and print
"underflow" if there is nothing to remove. For example
stu={1:56,2:45,3:78,4:65,5:35,6:90} values of stack_roll and stack_mark after push_stu()
[3,4,6] and [78,65,90]
33.