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')
: \# 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 hotelStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started