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

Python Files Exercises PDF

The document provides 20 Python programming exercises related to reading from, writing to, and manipulating text files. The exercises include reading an entire file or specific lines, appending text, storing file content in lists, arrays or variables, finding longest words or line counts, word frequency counting, file size checking, writing lists to files, copying files, combining lines from multiple files, random line selection, file closing validation, newline removal, word counting, character extraction, and alphabet listing.

Uploaded by

Sridhar Selvaraj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Python Files Exercises PDF

The document provides 20 Python programming exercises related to reading from, writing to, and manipulating text files. The exercises include reading an entire file or specific lines, appending text, storing file content in lists, arrays or variables, finding longest words or line counts, word frequency counting, file size checking, writing lists to files, copying files, combining lines from multiple files, random line selection, file closing validation, newline removal, word counting, character extraction, and alphabet listing.

Uploaded by

Sridhar Selvaraj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Files Exercises

1. Write a Python program to read an entire text file.

2. Write a Python program to read first n lines of a file.

3. Write a Python program to append text to a file and display


the text.

4. Write a Python program to read last n lines of a file.

5. Write a Python program to read a file line by line and store it


into a list.

6. Write a Python program to read a file line by line store it into


a variable.

7. Write a Python program to read a file line by line store it into


an array.

8. Write a python program to find the longest words.

9. Write a Python program to count the number of lines in a text


file.

10. Write a Python program to count the frequency of words in a


file.

11. Write a Python program to get the file size of a plain file.

12. Write a Python program to write a list to a file.

13. Write a Python program to copy the contents of a file to


another file .
14. Write a Python program to combine each line from first file
with the corresponding line in second file.

15. Write a Python program to read a random line from a file.

16. Write a Python program to assess if a file is closed or not.

17. Write a Python program to remove newline characters from


a file.

18. Write a Python program that takes a text file as input and
returns the number of words of a given text file.
Note: Some words can be separated by a comma with no
space.

19. Write a Python program to extract characters from various


text files and puts them into a list.

20. Write a Python program to create a file where all letters of


English alphabet are listed by specified number of letters on
each line.

You might also like