fname input('enter the file name'tryfhand open(fnameexceptprint('file cannot be opened:'fnameexit(counts dict(for line in fhandwords line split(for word in wordsif word not in countscounts[word elsecounts[word+ print(countscodein our else statementwe use the more compact alternative for incrementing variable counts[word+ is equivalent to counts[wordcounts[word either method can be used to change the value of variable by any desired amount similar alternatives exist for -=*=and /when we run the programwe see raw dump of all of the counts in unsorted hash order (the romeo txt file is available at www py com/code /romeo txtpython count py enter the file nameromeo txt {'and' 'envious' 'already' 'fair' 'is' 'through' 'pale' 'yonder' 'what' 'sun' 'who' 'but' 'moon' 'window' 'sick' 'east' 'breaks' 'grief' 'with' 'light' 'it' 'arise' 'kill' 'the' 'soft' 'juliet' it is bit inconvenient to look through the dictionary to find the most common words and their countsso we need to add some more python code to get us the output that will be more helpful looping and dictionaries if you use dictionary as the sequence in for statementit traverses the keys of the dictionary this loop prints each key and the corresponding valuecounts 'chuck 'annie 'jan' for key in countsprint(keycounts[key]