jfz-2023-s474155/TaskA02/run.py

61 lines
1.8 KiB
Python
Raw Normal View History

2023-10-30 11:58:07 +01:00
def checkForTFirstChar(char):
if char == 'p' or char == ' ':
return char
else:
return None
def checkForTLastSymbol(char):
interpunct = [',', '.', '!', '?', ' ', ')', ';', ':', '\t', '\n','-']
for j in range(len(interpunct)):
if char == interpunct[j]:
return char
return None
def whereIsPies(file):
with open(file, "r", encoding="utf-8") as sampleCheck:
line = 0
lineCount = 0
for row in sampleCheck:
line += 1
lastChar = ''
word = ''
for char in row.lower():
if lastChar == '' or lastChar == ' ':
if char == 'p':
word+=char
lastChar = char
elif lastChar == checkForTFirstChar(lastChar):
word+=char
lastChar = char
elif len(word) == 2 and word[1] == 'i' and char == 'e':
word+=char
lastChar = char
elif len(word) == 3 and word[2] == 'e' and char == 's':
word+=char
lastChar = char
elif len(word) == 4 and word[3] == 's' and checkForTLastSymbol(char) == char:
word+=char
lastChar = char
else:
word = ''
lastChar = ''
if len(word) >= 5 and word[0] == checkForTFirstChar(word[0]) and word[1] == 'i' and word[2] == 'e' and word[3] == 's' and word[4] == checkForTLastSymbol(word[4]):
lineCount+=1
print(lineCount,'.',line )
break
file = 'polish_wiki_excerpt.in'
whereIsPies(file)