1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Marrrta [24]
4 years ago
5

Next, copy in your strip_punctuation function and define a function called get_pos which takes one parameter, a string which rep

resents one or more sentences, and calculates how many words in the string are considered positive words. Use the list, positive_words to determine what words will count as positive. The function should return a positive integer - how many occurrences there are of positive words in the text. Note that all of the words in positive_words are lower cased, so you’ll need to convert all the words in the input string to lower case as well.
punctuation_chars = ["", ","," 3 # list of positive words to use 4 positive_words = 0 5 with open ("positive_words.txt") as pos_f: for lin in pos_f: if lin[0] != ';' and lin[0] != '\n': positive_words.append(lin.strip) 6 7 8 9 10
Computers and Technology
1 answer:
AlexFokin [52]4 years ago
6 0

Answer:

Here is the get_pos function:

def get_post(string):  #function that takes string as parameter

   string=string.lower() #converts the string to lower case                    

   string=strip_punctuation(string)  #calls strip_punctuation to remove punctuation from string

   string=string.split() #split the string into a list      

   count_positive=0  #counts the occurrences of positive words

   for word in string:  #loops through the string

       if word in positive_words:  #if a word in a string is a positive words

           count_positive=count_positive+1  #adds 1 to the count of count_positive each time a positive word appears

   return count_positive #returns the positive integer - how many occurrences there are of positive words in the string

Explanation:

In order to explain the working of this function lets suppose the punctuation_chars list contains the following punctuation characters:

punctuation_chars = ["'", '"', ",", ".", "!", ":","?", ";", '#']

Lets suppose the positive_words.txt file contains the following two words i.e. yes  okay

Lets suppose the string is Hi! I am okay, see you later.

string = " Hi! I am okay, see you later. "

string=string.lower()  statement converts the string to lower case:

string = hi! i am okay, see you later.

string=strip_punctuation(string)   this statement calls strip_punctuation method to remove the punctuation from string.

string = hi i am okay see you later

string=string.split() this statement splits the sentence into list

['hi', 'i', 'am', 'okay', 'see', 'you', 'later']  

for word in string: this loop iterates through the string

At first iteration if condition checks if word "hi" is in positive_words. This is not true because positive_words only contain the words okay and yes.

At next iteration if condition checks if word "i" is in positive_words. This is not true because positive_words only contain the words okay and yes.

At next iteration if condition checks if word "am" is in positive_words. This is also not true.

At next iteration if condition checks if word "okay" is in positive_words. This is true because positive_words contains the words okay. So count_positive=count_positive+1 statement executes which adds 1 to the count of count_positive so

count_positive = 1

At next iteration if condition if word in positive_words checks if word "see" is in positive_words. This is not true.

At next iteration if condition checks if word "you" is in positive_words. This is also not true.

At next iteration if condition checks if word "later" is in positive_words. This is also not true.

Now the statement:  return count_positive  returns the occurrence of positive words in the string which is 1. So the output of this is 1.

Here is the strip_punctuation method:

def strip_punctuation(word):  #removes punctuation from words

   New_word=""   #initializes new word string to empty

   print("Word is: ",word)  #prints the word

   for w in word:  #iterates through words

       if w not in punctuation_chars:  #if word is not in punctuation_char list

           New_word=New_word+w  #adds that word to new word string

   return  New_word #returns word after removing punctuation

You might be interested in
What is a neuromorphic chip?
Dominik [7]

Answer:

A neuromorphic computer is a machine comprising many simple processors / memory structures (e.g. neurons and synapses) communicating using simple messages (e.g. spikes). ... Neuromorphic computing systems excel at computing complex dynamics using a small set of computational primitives (neurons, synapses, spikes).

Explanation:

The structure of neuromorphic computers makes them much more efficient at training and running neural networks. They can run AI models at a faster speed than equivalent CPUs and GPUs while consuming less power. This is important since power consumption is already one of AI's essential challenges.

3 0
3 years ago
The cyclical, multistep process by which designers and engineers design, build, and taste a new product is called:
zzz [600]
The answer is Design Process.  <span>The cyclical, multistep process by which designers and engineers design, build, and taste a new product is called Design Process.   </span><span>There are multiple steps, including exploring, designing, planning, making, testing, and revising.</span>
7 0
3 years ago
What can you do to improve your own digital wellness?
julsineya [31]
Update your passwords frequently, delete unused accounts, and be diligent about who and what you give your most personal information to. Invest in tech that fits your lifestyle without offering further distractions.
4 0
3 years ago
Read 2 more answers
5. Write a function that takes two lists of integers and returns a list containing tuples with corresponding elements from both
Allisa [31]

Answer:

def corresponding_of_lists(lst1, lst2):

   c = ""

   corresponding_list = []

   if (lst1 is None) or (lst2 is None):

       return None

   else:

       for i in lst1:

           for j in lst2:

               c = "(" + str(i) + "," + str(j) + ")"

               corresponding_list.append(c)

   return corresponding_list

Explanation:

- Create a function called corresponding_of_lists that takes two lists as parameter

- Initialize an empty list to hold the corresponding values

- Check if any of the lists are null, if they are return None

- Otherwise, get the corresponding elements and put them into the corresponding_list

Return the corresponding_list

7 0
3 years ago
Which of the following actions is most likely to raise legal or ethical concerns?
zavuch27 [327]

Answer:

arson, kidnapping, gun fighting

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Using a text editor, create a file that contains a list of at least 15 six-digit account numbers. Read in each account number an
    12·1 answer
  • Which result would support the particle theory of light?
    6·2 answers
  • Please help me please and thank you!
    14·1 answer
  • Plz help! 3 questions! 1.The ideal light to use is.... A.front light B.a combination of side and back light C.a combination of f
    10·1 answer
  • Suppose you wanted to run a web server or ftp server from your home. what type of ip address would you want?​
    6·1 answer
  • Que Inventos Importantes se Crearon durante la edad de agua y viento
    11·1 answer
  • _______ allow(s) you to apply colorful, eye catching designs to a presentation all at once. A. Themes B. Slide orientation C. Th
    10·2 answers
  • Lydia noticed that she feels tired and out of breath after walking her dog up a hill in the park. Which area of fitness does she
    8·1 answer
  • A form letter can be customized by using different fields in a __________.
    15·2 answers
  • What component of a processor holds instructions waiting to be processed by the alu?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!