Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7&8 please by computing and returining the frequency with which specified words (wordlist) appear in a body of text (text). Frequency is the sum of

7&8 please image text in transcribed
image text in transcribed
by computing and returining the frequency with which specified words (wordlist) appear in a body of text (text). Frequency is the sum of the number of times that each word in wordlist occurs, divided by the number of words in the text. A word occurrence is the whote word, regardless of case, and excluding punctuation. Ni. probleM 1. Write a string method call that tower cases atl F of the characters in text. One line of code. Hint: assign the * lower-cased text to a new variabte nane. mixedText = "THIS, is a LMIX-EO Charac-TER" lower_cased_text m mixedText. Lower () print(tower_cased_text) 2 PROBLEM 2. Write a string method call that replaces every * m-dash ('.-) in the lower-cased text with a space (" " "). * One line of code. 7. PROBL.EM 3. Write a string method catl that splits text into a * list of words (after they have been lower-cased, and the * a-dashes removed). One line of code. word _ist =replacedText. printit (word prist) * PROBLEM 4. Write a loop that creates a new word list, using a * string method to strip the words from the list created in Rroblem 3 F of ath leading and trailing punctuation. Hint: the string library, = Which is imported above, contains a constant named punctuation. = Three tines of code. new_word_Lis t f [ ] for_word in word tist: new_word_List. append(word.strip(string.punctuation)) print (new_word_List) * PROELEM 5. Write a loop that sums the nunber of times that the * words in wordtist occur in the tist from Problen 4. Hint 1: you * can use a list method to do the counting. Hint 2: lower case the \# words in wordlist. Between three and five lines of code. (It) * depends on your coding style - various styles are oK.) tota=a fer word in word List: total = totat + word__ist. count (word) print ("The sue of the number of times the words in wordlist occur is: ", total) 7. PRoslek 6. Calculate the ratio of the number from Problen 5 Fo the number of words in text. Retura this ratio. Between one F and three lines of code. (It depends on your coding style Chtigethetioc): print("The reguired ratio-isti ist, getRatiof)) * Fhobler zicint isterierriendof faur tises to find the frequency \# PROBLEM 6. Calculate the ratio of the number from Problem 5 \# to the number of words in text. Return this ratio. Between one \# and three lines of code. (It depends on your coding style -- \# various styles are OK.) def getRatio(): return total/len(word_iist) print("The required ratio is: ", getRatio()) \# PROBLEM 7. Call litCricFriend() four times to find the frequency \# of the indefinite articles ' a ' and 'an' and the definite article \# 'the' in the two poems above. Print out the value returned by \# each function call, identifying what it is. For example, it might say # bellsAAnFrequency 0.07265587064676617. \# (That is a made-up number.) Each function call takes one line. \# PROBLEM 8. Do the results show that Poe and Neruda use ' a ' and 'an' \# differently? Do the results show that Poe and Neruda use 'the' Put your answer to PROBLEM 8 here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions