From 5c739e9cf709c3489b0ba32eef50f055277e08b7 Mon Sep 17 00:00:00 2001 From: IgnBys Date: Sat, 28 Oct 2023 23:13:15 +0200 Subject: [PATCH] First commit --- TaskA01/Task1.py | 28 ++++++++++++++++++++++++++++ TaskA02/TaskAO2.py | 31 +++++++++++++++++++++++++++++++ TaskA02/simple.exp | 2 +- TaskA02/test.py | 2 ++ TaskA03/TaskAO3.py | 43 +++++++++++++++++++++++++++++++++---------- 5 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 TaskA01/Task1.py create mode 100644 TaskA02/TaskAO2.py create mode 100644 TaskA02/test.py diff --git a/TaskA01/Task1.py b/TaskA01/Task1.py new file mode 100644 index 0000000..f11a241 --- /dev/null +++ b/TaskA01/Task1.py @@ -0,0 +1,28 @@ + +def openFile(fileName,hamletArray = ['H','a', 'm', 'l', 'e', 't']): + with open(fileName, "r", encoding="utf-8") as file: + for row in file: + repCounter = 0 + counter = 0 + checkWord ='' + for i in row: + if i == hamletArray[counter]: + checkWord+=i + counter+=1 + if checkWord == 'Hamlet': + checkWord = '' + counter = 0 + repCounter+=1 #if in one row more than one Hamlet it will write the row only once + if repCounter == 1: + print(row.strip()) + else: + checkWord = '' + counter = 0 +print('---------------------SHAKESPEARE.EXP--------------------------------------') +openFile('shakespeare.exp') +print('----------------------SHAKESPEARE.EXP-----------------------------------') +openFile('shakespeare.in') +print('------------------------SIMPLE.IN------------------------------------') +openFile('simple.in') +print('-----------------------SIMPLE.EXP--------------------------------------') +openFile('simple.exp') \ No newline at end of file diff --git a/TaskA02/TaskAO2.py b/TaskA02/TaskAO2.py new file mode 100644 index 0000000..f5275e9 --- /dev/null +++ b/TaskA02/TaskAO2.py @@ -0,0 +1,31 @@ +import re + + +def openFile(fileName,piesArray1 = [' ', 'P', 'p', '('], + piesArray2 = ['i', 'e', 's'], + piesArray3 = ['\t', '\n', '.', ',', ';', '!', '?', ')']): + with open(fileName, "r", encoding="utf-8") as file: + file_contents = file.read() + for row in file: + piesArrayCounter = 0 + repCounter = 0 + counter = 0 + checkWord = '' + for character in row: + if character == ' ': + checkWord+=character + if counter == 0 and checkWord == ' ': + if (character == 'P' or character == 'p'): + counter +=1 + + + + +print('---------------------SHAKESPEARE.EXP--------------------------------------') +openFile('shakespeare.exp') +print('----------------------SHAKESPEARE.EXP-----------------------------------') +openFile('shakespeare.in') +print('------------------------SIMPLE.IN------------------------------------') +openFile('simple.in') +print('-----------------------SIMPLE.EXP--------------------------------------') +openFile('simple.exp') \ No newline at end of file diff --git a/TaskA02/simple.exp b/TaskA02/simple.exp index 7b3620b..303b25e 100644 --- a/TaskA02/simple.exp +++ b/TaskA02/simple.exp @@ -1,3 +1,3 @@ Pies ma Alę Kot i pies to zwierzęta -pies +(pies) diff --git a/TaskA02/test.py b/TaskA02/test.py new file mode 100644 index 0000000..b3c7cd7 --- /dev/null +++ b/TaskA02/test.py @@ -0,0 +1,2 @@ +str = r'[Pp ]ies ' +print(len(str)) \ No newline at end of file diff --git a/TaskA03/TaskAO3.py b/TaskA03/TaskAO3.py index 3165de5..bf02b81 100644 --- a/TaskA03/TaskAO3.py +++ b/TaskA03/TaskAO3.py @@ -1,22 +1,45 @@ -def openFile(fileName, ageArray = ['1', '9', '[0123456789]', '[0123456789]', ' ', 'r', '.']): + + +def checkNumber(i): + if (i == '0' + or i == '1' + or i == '2' + or i == '3' + or i == '4' + or i == '5' + or i == '6' + or i == '7' + or i == '8' + or i == '9'): + return i +def openFile(fileName, ageArray = ['1', '9', None, None, ' ', 'r', '.']): with open(fileName, "r", encoding="utf-8") as file: for row in file: repCounter = 0 counter = 0 checkWord =[] for i in row: - if i in ageArray[counter]: - checkWord+=i - counter +=1 - if counter == 7: - repCounter+=1 + if counter != 2 and counter !=3: + if i == ageArray[counter]: + checkWord+=i + counter +=1 + else: checkWord = [] counter = 0 - if repCounter == 1: - print(row.strip()) + if counter == 7: + repCounter+=1 + checkWord = [] + counter = 0 + if repCounter == 1: + print(row.strip()) + else: - checkWord = [] - counter = 0 + if i==checkNumber(i): + checkWord+=i + counter+=1 + else: + checkWord = [] + counter = 0 print('---------------------SHAKESPEARE.EXP--------------------------------------') openFile('polish_wiki_excerpt.exp')