jfz-2023-s473616/TaskA01/run.py

20 lines
588 B
Python
Raw Normal View History

2023-10-28 18:05:08 +02:00
def contains_word(to_be_checked: str, word: str) -> bool:
word_len: int = len(word)
word_character_number: int = 0
for c in to_be_checked:
if c != word[word_character_number]:
word_character_number = 0
continue
if word_character_number == word_len - 1:
return True
word_character_number += 1
return False
file = open('shakespeare.exp', 'r', encoding='utf8')
result = []
line_number = 0
for line in file:
if contains_word(line, 'Hamlet'):
result.append(line_number)
line_number += 1
print(result)