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

Exercise 5

The document outlines a series of programming exercises in Python. Tasks include counting words in a text file, finding occurrences of a specific word, managing directories and files, and computing the average of floating point numbers from a file. Each exercise is designed to enhance file handling and directory management skills in Python.

Uploaded by

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

Exercise 5

The document outlines a series of programming exercises in Python. Tasks include counting words in a text file, finding occurrences of a specific word, managing directories and files, and computing the average of floating point numbers from a file. Each exercise is designed to enhance file handling and directory management skills in Python.

Uploaded by

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

Exercise -5

1. Write a program in Python to count and display the total number of words in a text
file.
2. Write a program in Python to read lines from a text file "notes.txt". Your function
should find and display the occurrence of the word "the".

For example: If the content of the file is:


"India is the fastest-growing economy. India is looking for more investments around
the globe. The whole world is looking at India as a great market. Most of the Indians
can foresee the heights that India is capable of reaching.

The output should be 5.

3. Write a program
a. To print the names of all the items in the current working directory using
os.listdir().
b. Create a new directory within the current working directory only after
checking if the directory already exists or not.
c. To rename the file “oldfile.txt” to “newfile.txt” within the new directory.
d. To remove the file “newfile.txt”.
e. To remove the new directory that was created on 5.b.

4. Create text file containing at least 100 floating point numbers and name it
‘example3.txt’. Now, write a program to access the file and compute the average of
all the numbers within the text file.

You might also like