0% found this document useful (0 votes)
13 views1 page

WS TXT Ii

Uploaded by

mjain1305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

WS TXT Ii

Uploaded by

mjain1305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Worksheet-I

Topic: File Handling in Python (Text Files)

1. Write a program to write three lines of text to a file ‘abc.txt’ using writelines() method.

2. Write a program to calculate the sum of two numbers entered by the user and write the result to
a file named ‘result.txt’.

3. What is the advantage of using ‘with’ statement along with open function?

4. Why is it important to close a file in Python?

5. Write a program to append data to file ‘abc.txt’. Also read the final contents of the file and display them.

7. What is the use of seek() and tell() methods?Give syntax.

8. Write a user defined function countP() in Python that displays the number of lines starting with ‘P’
in a file ‘Para.txt’.

9. Define the terms ‘Relative’ path and ‘Absolute’ path.

10. Write a function Func1() in Python to write multiple lines of text to a file ‘myfile.txt till the user wishes to continue.
Also, display the total number of lines written by the user.(Hint: use write() method)

You might also like