Question: My Question: Complete the loop below to display the number of times bathroom is contained within the text of the reviews for this hotel. I

My Question: Complete the loop below to display the number of times "bathroom" is contained within the text of the reviews for this hotel.

I should get 29 as the number of bathrooms, I am not sure where I am going wrong in writing the code.

See image below, the original file is not included.

When writing the code, I need to do the following: 1. Remove special characters ( For example, bathtub/bathroom => This may not be counted since it will consider it as one word) 2. Use split method to get words 3. Include "bathrooms" in your count

The code below is not correct, it outputs 18 as the count for "bathrooms".

for review in comment_lst:

# Split the current review into a list of words words = review.split()

# Count the number of times "bathroom" appears in the list of

words count = words.count("bathroom")

# Increment the counter variable by the count

counter += count

# Print the final count

print(f'The word bathroom occurs {counter} times in the reviews for this hotel')

My Question: Complete the loop below to display the number of times

: \# Find how many times the string "we" is mentioned in the comments. first_comment.count("we") [34]:2 M \# If we wanted a "case-insensitive" search of instances of "we", we can do this... first_comment.lower().count("we") \# include "We" as well [35]:7 Problem 2 (2 pts.): Complete the loop below to display the number of times "bathroom" is contained within the text of the reviews for this hotel. Your output should look like this: The word 'bathroom' occurs 29 times in the reviews for this hotel. I counter =0 for review in comment_lst: \#TODO: Insert code in the for loop body to determine the number of times "bathroom" appears \#in the current review and increment the counter variable accordingly. words=review.split() count=words . count ("bathroom") counter += count \# TODO: Print using an f-string print(f'The word bathroom occurs \{counter\} times in the reviews for this hotel') The word bathroom occurs 18 times in the reviews for this hotel

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!