jfz-2023-s464983/TaskA02/run.py
2023-10-29 22:02:40 +01:00

25 lines
864 B
Python

def findPies(filename):
target = "pies"
target_length = len(target)
with open(filename, 'r', encoding="utf-8") as file:
line_number = 1
for line in file:
for i in range(len(line) - target_length + 1):
match = (
(line[i] == 'p' or line[i] == 'P') and
(line[i + 1] == 'i' or line[i + 1] == 'I') and
(line[i + 2] == 'e' or line[i + 2] == 'E') and
(line[i + 3] == 's' or line[i + 3] == 'S')
)
start = i == 0 or line[i - 1] == ' '
end = i + target_length == len(line) or line[i + target_length] == ' '
if match and (start or end):
print(f"Line {line_number}")
break
line_number += 1
findPies('TaskA02/simple.in')