# words.py # Prints information about the words in a text file. def fileInfo(): fname = input("Enter filename: ") infile = open(fname,'r') lineCount = 0 wordCount = 0 charCount = 0 wordDict = {} for line in infile: lineCount = lineCount + 1; wordList= line.split() wordCount = wordCount + len(wordList) charLineCount = 0 for word in wordList: charCount = charCount + len(word) charLineCount = charLineCount + len(word) word = word.lower() word = word.replace(",","") if word in wordDict: wordDict[word] += 1 else: wordDict[word] = 1 # print ("Chars:", charLineCount, line[:-1]) print ("The number of lines is: ", lineCount) print ("The number of words is: ", wordCount) print ("The number of characters is: ", charCount) print ("The average number of words per line is: ", wordCount/float(lineCount)) print ("The average number of letters per word is: ", charCount/float(wordCount)) words = list(wordDict.keys()) words.sort() for word in words: if wordDict[word] > 100: print(word, " ", wordDict[word])