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?
# 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}')
Comments
Leave a comment