jfz-2023-s473579/TaskA02/run.py

68 lines
2.3 KiB
Python
Raw Normal View History

2023-10-29 10:11:56 +01:00
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 == '?'
2023-10-30 09:43:42 +01:00
or character == '-'
2023-10-29 10:11:56 +01:00
or character == ')'):
return character
else:
return None
def openFile(fileName):
2023-10-20 17:24:11 +02:00
with open(fileName, "r", encoding="utf-8") as file:
for row in file:
2023-10-29 10:11:56 +01:00
lastWordSymbol = ''
2023-10-20 17:24:11 +02:00
counter = 0
2023-10-29 10:11:56 +01:00
checkWord = []
2023-10-20 17:24:11 +02:00
for i in row:
2023-10-29 10:11:56 +01:00
if lastWordSymbol == '' or lastWordSymbol == ' ':
if i == 'P' or i=='p':
2023-10-20 17:24:11 +02:00
checkWord+=i
2023-10-29 10:11:56 +01:00
lastWordSymbol = i
2023-10-20 17:24:11 +02:00
2023-10-29 10:11:56 +01:00
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
2023-10-20 17:24:11 +02:00
else:
2023-10-29 10:11:56 +01:00
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
2023-10-20 17:24:11 +02:00
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')