Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone correct this code please because it wont run i attached the instructions import string def litcricFriend(wordList, text): #Problem 1 txt = text.lower) #Problem

can someone correct this code please because it wont run
i attached the instructions image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
import string def litcricFriend(wordList, text): #Problem 1 txt = text.lower) #Problem 2 txt = txt.replace('','') #Problem 3 txt = txt.split() #Problem 4 cleanlist = 0 for words in txt: cleanlist.append(word.strip(string.punctuation)) #Problem 5 count = 0 for word in wordlist: count to cleanlist.count(word.lower()) #Problem 6 ratio = count len(cleanlist) return ratio #Problem 7 print(litCricFriend(['A', 'An'), the Bells)) print(litCricFriend ([THE'), theBells)) a print(litCricFriend(['a', 'an'), cantoXII)) print(litCricFriend (['the!), cantoXII)) def litcricFriend(wordList, text): The Literary Critic's Friend helps the humanities scholar by computing and returning 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 whole word, regardless of case, and excluding punctuation.'' # PROBLEM 1. Write a string method call that lower cases all # of the characters in text. One line of code. Hint: assign the # lower-cased text to a new variable name. arte name # PROBLEM 2. Write a string method call that replaces every # m-dash ('--') in the lower-cased text with a space (' '). # One line of code. # PROBLEM 3. Write a string method call that splits text into a # list of words (after they have been lower-cased, and the # m-dashes removed). One line of code. # PROBLEM 4. Write a loop that creates a new word list, using a # string method to strip the words from the list created in Problem 3 # of all leading and trailing punctuation. Hint. the string library, # which is imported above, contains a constant named punctuation. Three lines of code # PROBLEM 5. Write a loop that sums the number of times that the # words in wordList occur in the list from Problem 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.) # 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 -- COOH # various styles are OK. ) # 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 # various styles are OK.) # 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 # differently? 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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions