Answer to Question #292075 in Python for Akhilesh

Question #292075

Ram challenges Anil to a game he decides to give a target word w to Anil .the rules of the game are very simple ram gives Anil n sentence one by one and asks Anil to print the first sentence which contains the given word w. If the sentence numbering starts from 1, can you identify the first sentence. Number containing the word W?

1
Expert's answer
2022-01-30T07:24:12-0500
# Python 3.9.5

sen_list = [
    'If you are working with Python, there is no escaping from the word self.',
    'It is used in method definitions and in variable initialization.',
    'The self method is explicitly used every time we define a method.'
]

w = 'word'

for i in range(1, len(sen_list)+1):
    if w in sen_list[i-1]:
        print(f'Sentence number {i} has a given word')
    else:
        print(f'This word is not mentioned in sentences {i}')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS