def checkFirstSymbol(character):
    if character == 'P' or character == 'p' or character == ' ':
        return character
    else:
        return None

def checkLastSymbol(character):
    if (character == '\t'
        or character == '\n'
        or character == '.'
        or character == ','
        or character == ';'
        or character == '!'
        or character == ' '
        or character == '?'
        or character == '-'
        or character == ')'):
        return character
    else:
        return None
def openFile(fileName):
    with open(fileName, "r", encoding="utf-8") as file:
        for row in file:
            lastWordSymbol = ''
            counter = 0
            checkWord = []
            for i in row:
                if lastWordSymbol == '' or lastWordSymbol == ' ':
                    if i == 'P' or i=='p':
                        checkWord+=i
                        lastWordSymbol = i

                elif lastWordSymbol == checkFirstSymbol(lastWordSymbol):
                    checkWord += i
                    lastWordSymbol = i
                elif lastWordSymbol == 'i' and i=='e':
                    checkWord += i
                    lastWordSymbol = i
                elif lastWordSymbol == 'e' and i == 's':
                    checkWord += i
                    lastWordSymbol = i
                elif lastWordSymbol == 's' and i == checkLastSymbol(i):
                    checkWord += i
                    lastWordSymbol = i
                else:
                    checkWord=[]
                    lastWordSymbol=''
                if (len(checkWord)>=5 and checkWord[0]==checkFirstSymbol(checkWord[0])
                        and checkWord[1] == 'i'
                        and checkWord[2] == 'e'
                        and checkWord[3] == 's'
                        and checkWord[4] == checkLastSymbol(checkWord[4])):
                    print(row, end ='')
                    break





print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('polish_wiki_excerpt.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('polish_wiki_excerpt.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')
