Reference no: EM132212214
Question :
You have to write a Python program (3.5) which take two text files and compare them. you should revise the code to write some sensibly-designed reusable functions instead of simply duplicating each chunk of code and changing variable names.
Revise and enhance the program so that the program ALSO does these things:
1. Ask the user for a second text file to compare with the first one. I'll refer to the files "A" and "B" below.
2. Calculate the word frequency for text "B" in the same way it does for "A".
3. For both files, compute and print out how many total words it contains and how many distinct words they contain.
4. For both files, print out the n most frequent individual words (sorted like the provided example already does), but also showing the percentage of the total words each represents in its file. This is simple to calculate, as: frequency_of_word / total_words * 100. Round that to 2 decimal places.
5. Last, as a simple comparison of the texts, your program should print all the words that occured more than once in text "A" but not at all in "B" and vice-versa.