Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ======== RESTART: D:\CSI31F18\sample pgms\code\chapter11\wordfreq.py ======== This program analyzes word frequency in a file and prints a report on the n most frequent words. File to analyze: frank.txt Traceback (most recent call last): File "D:\CSI31F18\sample pgms\code\chapter11\wordfreq.py", line 32, in if __name__ == '__main__': main() File "D:\CSI31F18\sample pgms\code\chapter11\wordfreq.py", line 12, in main text = open(fname,'r').read() FileNotFoundError: [Errno 2] No such file or directory: 'frank.txt' >>> ======== RESTART: D:\CSI31F18\sample pgms\code\chapter11\wordfreq.py ======== This program analyzes word frequency in a file and prints a report on the n most frequent words. File to analyze: frank1.txt Output analysis of how many words? 25 the 339 of 246 and 236 to 231 i 194 a 178 my 165 in 127 he 92 his 91 that 86 as 64 but 63 was 62 which 61 you 61 her 60 with 59 me 57 for 56 have 55 on 55 had 52 is 50 by 48 >>> numslist = [] >>> from random import randrange >>> for k in range(100): numslist.append(randrange(100)) >>> numslist [67, 76, 45, 26, 83, 66, 22, 24, 85, 48, 8, 15, 47, 50, 57, 68, 34, 94, 27, 72, 84, 28, 69, 64, 94, 58, 38, 31, 74, 81, 53, 70, 26, 3, 43, 15, 62, 34, 78, 95, 13, 40, 56, 41, 32, 79, 17, 80, 14, 62, 20, 75, 5, 63, 93, 35, 54, 11, 37, 68, 54, 90, 14, 24, 40, 10, 33, 37, 77, 89, 92, 11, 71, 10, 95, 48, 74, 78, 52, 81, 33, 91, 69, 99, 95, 43, 98, 69, 18, 17, 33, 78, 71, 36, 40, 99, 33, 7, 69, 95] >>> for k in numslist: if k < 50: print(k) 45 26 22 24 48 8 15 47 34 27 28 38 31 26 3 43 15 34 13 40 41 32 17 14 20 5 35 11 37 14 24 40 10 33 37 11 10 48 33 43 18 17 33 36 40 33 7 >>> for index in range(len(numslist)): if numslist[index] < 50: print(numslist[index]) 45 26 22 24 48 8 15 47 34 27 28 38 31 26 3 43 15 34 13 40 41 32 17 14 20 5 35 11 37 14 24 40 10 33 37 11 10 48 33 43 18 17 33 36 40 33 7 >>> index = 0 >>> while index < len(numslist): if numslist[index] < 50: print(numslist[index]) index = index + 1 45 26 22 24 48 8 15 47 34 27 28 38 31 26 3 43 15 34 13 40 41 32 17 14 20 5 35 11 37 14 24 40 10 33 37 11 10 48 33 43 18 17 33 36 40 33 7 >>> index = 0 >>> count = 0 >>> while index < len(numslist) and count < 10: if numslist[index] < 50: print(numslist[index]) count = count + 1 index = index + 1 45 26 22 24 48 8 15 47 34 27 >>> text = "For our purposes, a sentence is the sequence of words between one period, exclamation point or question make, and the next one. The program as written first breaks the text into a list of words without any punctuation or special characters. To compute the length of sentences with our definition, you should leave in periods, exclamation points, and question marks at first in order to do the counting, and then remove them later. " >>> for ch in '!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~': text = text.replace(ch, ' ') >>> text 'For our purposes a sentence is the sequence of words between one period exclamation point or question make and the next one The program as written first breaks the text into a list of words without any punctuation or special characters To compute the length of sentences with our definition you should leave in periods exclamation points and question marks at first in order to do the counting and then remove them later ' >>> text ="For our purposes, a sentence is the sequence of words between one period, exclamation point or question make, and the next one. The program as written first breaks the text into a list of words without any punctuation or special characters. To compute the length of sentences with our definition, you should leave in periods, exclamation points, and question marks at first in order to do the counting, and then remove them later. " >>> for ch in '"#$%&()*+,-/:;<=>@[\\]^_`{|}~': text = text.replace(ch, ' ') >>> text 'For our purposes a sentence is the sequence of words between one period exclamation point or question make and the next one. The program as written first breaks the text into a list of words without any punctuation or special characters. To compute the length of sentences with our definition you should leave in periods exclamation points and question marks at first in order to do the counting and then remove them later. ' >>> text = text.split() >>> text ['For', 'our', 'purposes', 'a', 'sentence', 'is', 'the', 'sequence', 'of', 'words', 'between', 'one', 'period', 'exclamation', 'point', 'or', 'question', 'make', 'and', 'the', 'next', 'one.', 'The', 'program', 'as', 'written', 'first', 'breaks', 'the', 'text', 'into', 'a', 'list', 'of', 'words', 'without', 'any', 'punctuation', 'or', 'special', 'characters.', 'To', 'compute', 'the', 'length', 'of', 'sentences', 'with', 'our', 'definition', 'you', 'should', 'leave', 'in', 'periods', 'exclamation', 'points', 'and', 'question', 'marks', 'at', 'first', 'in', 'order', 'to', 'do', 'the', 'counting', 'and', 'then', 'remove', 'them', 'later.'] >>> len(text) 73 >>> for each in text: print(each) For our purposes a sentence is the sequence of words between one period exclamation point or question make and the next one. The program as written first breaks the text into a list of words without any punctuation or special characters. To compute the length of sentences with our definition you should leave in periods exclamation points and question marks at first in order to do the counting and then remove them later. >>> for k in range(len(text)): print(k, text[k]) 0 For 1 our 2 purposes 3 a 4 sentence 5 is 6 the 7 sequence 8 of 9 words 10 between 11 one 12 period 13 exclamation 14 point 15 or 16 question 17 make 18 and 19 the 20 next 21 one. 22 The 23 program 24 as 25 written 26 first 27 breaks 28 the 29 text 30 into 31 a 32 list 33 of 34 words 35 without 36 any 37 punctuation 38 or 39 special 40 characters. 41 To 42 compute 43 the 44 length 45 of 46 sentences 47 with 48 our 49 definition 50 you 51 should 52 leave 53 in 54 periods 55 exclamation 56 points 57 and 58 question 59 marks 60 at 61 first 62 in 63 order 64 to 65 do 66 the 67 counting 68 and 69 then 70 remove 71 them 72 later. >>> text ['For', 'our', 'purposes', 'a', 'sentence', 'is', 'the', 'sequence', 'of', 'words', 'between', 'one', 'period', 'exclamation', 'point', 'or', 'question', 'make', 'and', 'the', 'next', 'one.', 'The', 'program', 'as', 'written', 'first', 'breaks', 'the', 'text', 'into', 'a', 'list', 'of', 'words', 'without', 'any', 'punctuation', 'or', 'special', 'characters.', 'To', 'compute', 'the', 'length', 'of', 'sentences', 'with', 'our', 'definition', 'you', 'should', 'leave', 'in', 'periods', 'exclamation', 'points', 'and', 'question', 'marks', 'at', 'first', 'in', 'order', 'to', 'do', 'the', 'counting', 'and', 'then', 'remove', 'them', 'later.'] >>> beg = 0 >>> end = 0 >>> for end < len(text): SyntaxError: invalid syntax >>> beg = 0 >>> end = 0 >>> while end < len(text): if text[end][-1] == '.': print("sentennce begins at", beg, 'ends at', end) beg = end +1 end = end + 1 sentennce begins at 0 ends at 21 sentennce begins at 22 ends at 40 sentennce begins at 41 ends at 72 >>> beg = 0 >>> end = 0 >>> if text[end][-1] == '.': print("begins at ", beg, "ends at ", end) beg = beg + 1 text[end] = text[end][0:-1] end = end + 1 SyntaxError: unindent does not match any outer indentation level >>> if text[end][-1] == '.': print("begins at ", beg, "ends at ", end) beg = beg +1 text[end] = text[end][0:-1] >>> text ['For', 'our', 'purposes', 'a', 'sentence', 'is', 'the', 'sequence', 'of', 'words', 'between', 'one', 'period', 'exclamation', 'point', 'or', 'question', 'make', 'and', 'the', 'next', 'one.', 'The', 'program', 'as', 'written', 'first', 'breaks', 'the', 'text', 'into', 'a', 'list', 'of', 'words', 'without', 'any', 'punctuation', 'or', 'special', 'characters.', 'To', 'compute', 'the', 'length', 'of', 'sentences', 'with', 'our', 'definition', 'you', 'should', 'leave', 'in', 'periods', 'exclamation', 'points', 'and', 'question', 'marks', 'at', 'first', 'in', 'order', 'to', 'do', 'the', 'counting', 'and', 'then', 'remove', 'them', 'later.'] >>> ======================= RESTART: D:/CSI31F18/delete.py ======================= ['For', 'our', 'purposes', 'a', 'sentence', 'is', 'the', 'sequence', 'of', 'words', 'between', 'one', 'period', 'exclamation', 'point', 'or', 'question', 'make', 'and', 'the', 'next', 'one.', 'The', 'program', 'as', 'written', 'first', 'breaks', 'the', 'text', 'into', 'a', 'list', 'of', 'words', 'without', 'any', 'punctuation', 'or', 'special', 'characters.', 'To', 'compute', 'the', 'length', 'of', 'sentences', 'with', 'our', 'definition', 'you', 'should', 'leave', 'in', 'periods', 'exclamation', 'points', 'and', 'question', 'marks', 'at', 'first', 'in', 'order', 'to', 'do', 'the', 'counting', 'and', 'then', 'remove', 'them', 'later.'] >>>