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

Which of The Following Functions Changes The Position of File Pointer and Returns Its New Position

The document contains questions about Python file handling functions and concepts. It asks about functions like tell(), seek(), opening modes like r+ and w+, and writing functions to work with CSV and binary files. It also contains questions about the differences between text and binary files, and using seek() to change the file pointer position.

Uploaded by

Monica Sree
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Which of The Following Functions Changes The Position of File Pointer and Returns Its New Position

The document contains questions about Python file handling functions and concepts. It asks about functions like tell(), seek(), opening modes like r+ and w+, and writing functions to work with CSV and binary files. It also contains questions about the differences between text and binary files, and using seek() to change the file pointer position.

Uploaded by

Monica Sree
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

Which of the following functions changes the position of file pointer and returns its new
position? a.flush() b.tell() c.seek() d.offset()
2. Write a function in Python to read a text file, Alpha.txt and displays those lines which
begin with the word ‘You’.
3. Write a function, vowelCount() in Python that counts and displays the number of vowels in
the text file named Poem.txt.
4. Vedansh is a Python programmer working in a school. For the Annual Sports Event, he has
created a csv file named Result.csv, to store the results of students in different sports
events. The structure of Result.csv is:

[St_Id, St_Name, Game_Name, Result]

Where St_Id is Student ID (integer)

ST_name is Student Name (string)

Game_Name is name of game in which student is participating(string)

Result is result of the game whose value can be either 'Won', 'Lost' or 'Tie'

For efficiently maintaining data of the event, Vedansh wants to write the following user defined
functions:

Accept() – to accept a record from the user and add it to the file Result.csv. The column headings
should also be added on top of the csv file.

wonCount() – to count the number of students who have won any event. As a Python expert,
help him complete the task.

5. Differentiate between r+ and w+ file modes in Python.


6. Consider a file, SPORT.DAT, containing records of the following structure: [SportName,
TeamName, No_Players] Write a function, copyData(), that reads contents from the file
SPORT.DAT and copies the records with Sport name as “Basket Ball” to the file named
BASKET.DAT. The function should return the total number of records copied to the file
BASKET.DAT.
7. How are text files different from binary files? (ii) A Binary file, CINEMA.DAT has the following
structure: {MNO:[MNAME, MTYPE]} Where MNO – Movie Number MNAME – Movie Name
MTYPE is Movie Type Write a user defined function, findType(mtype), that accepts mtype as
parameter and displays all the records from the binary file CINEMA.DAT, that have the value
of Movie Type as mtype.
8. Which of the following mode in file opening statement results or generates an error if the file
does not exist? (a) a+ (b) r+ (c) w+ (d) None of the above
9. The correct syntax of seek() is: (a) file_object.seek(offset [, reference_point]) (b) seek(offset
[, reference_point]) (c) seek(offset, file_object) (d) seek.file_object(offset
10. Assertion (A): CSV (Comma Separated Values) is a file format for data storage which looks like
a text file. Reason (R): The information is organized with one record on each line and each
field is separated by comma.
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

You might also like