Sunday, 19 December 2021

Python with functions to calculate: 3rd Maximum number, 9th Minimum number, Total Unique Count in a text file(.txt)

 To execute this lab you need to upload a text file to Jupyter note Book. Here are steps how to upload file to Jupyter note books. To do this you need a file, so click here to download the file

1. After loading the Jupyter, on the right side click on upload button

2. It will opens a " File upload" dialog box. Select the file and click on open.

3.  Then in the Jupyter note book file list you see a blue colored upload button click on it to complete file upload.

The following are the steps to find 3rd maximum and 9th minimum number, also unique count.

1. Open the text file in read mode. ( the file mode is "rt")

2. The read the file data using read function.

3. Split the data using split function space as separator

4. After display the data

5. Then sort the splited data. Now all the data in the sorted format in the array.

6. By using array index property display the required numbers 

The following program illustrates above steps

import statistics
file = open("numbers1.txt", "rt")
data =
words = data.split()

print('words in text file :', words)
length = len(words)

print("Third Largest element is:", words[length-3])
print("Ninth minimum element is:", words[length-2])
print("Number of element is:", length)

The following is the output

words in text file : ['1', '2', '3', '4', '5', '6', '7', '8', '9']
Third Largest element is: 7
Ninth minimum element is: 8
Number of element is: 9



Post a Comment

Note: only a member of this blog may post a comment.

Find Us On Facebook

python tutorial


C Programming


Java Tutorial


Data Structures


MS Office


Database Management