Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

My Question: 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:

Based on the code I wrote, it's giving me 26, however I should get 29, I am not sure where I am going wrong in writing the code. See image below, the original file is not included.

image text in transcribed

We we want to iterate over the list of comments and obtain information about the comments made by the reviewers. Since each of the comments is a String object, we are going to need some String methods to extract the information. See, for example, Let us illustrate some of the listed methods with the comments from the first reviewer. M \# Create a new string with all characters made lower case.. first_comment.lower() 'we enjoyed the best western pioneer square. my husband and i had a room with a king bed and it was clean, quiet, and attr ctive. our sons were in a room with twin beds. their room was in the corner on the main street and they said it was a litt. e noisier and the neon light shone in. but later hotels on the trip made them appreciate this one more. we loved the old wr od center staircase. breakfast was included and everyone was happy with waffles, toast, cereal, and an egg meal. location as great. we could walk to shops and restaurants as well as transportation. pike market was a reasonable walk. we enjoyed he nearby gold rush museum. very, very happy with our stay. staff was helpful and knowledgeable.' M \# Find how many times the string "we" is mentioned in the comments. first_comment.count("we") ]: 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 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. M 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. # Listed_str = review. sp Lit () \# instance_value = Listed_str.count("bathroom") \# counter = counter + instance _value if 'bathroom' in review. lower(): counter +=1 \# TOD0: Print using an f-string print( f 'The word bathroom occurs \{counter\} times in the reviews for this hotel') The word bathroom occurs 26 times in the reviews for this hotel

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

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions