I am currently trying to solve some beginners exercises but I am stuck at the point where I am supposed to expand an existing function and also add the string that allows me to ignore upper and lower cases. I do really do not know where in the function I should be adding this last information. I am also supposed to find all the lines where the words appear ('Heaven', 'all', 'you').
Here is what I have now:
def all_line_numbers(text, word):
"""
Returns the line numbers (beginning with 1) where the word appears in
:param text: Text in which the word is searched for
:param word: A word to search for
:return: List of line numbers
"""
lines = text.splitlines()
i = 0
for line in lines:
i = i + 1
if word in line:
return i
return []
and it ends with:
#
print()
print("exercise")
words = ['Heaven', 'all', 'you']
for word in words:
num = all_line_numbers(it_rains, word)
if num:
print(f"The word {word} is in the following lines {num}.")
else:
print(f"The word {word} was not found!")
Thank you very much in advance!