From 92361f3372bfdd50a99a36a032ab45c4c8bf8427 Mon Sep 17 00:00:00 2001 From: IgnBys Date: Wed, 18 Oct 2023 22:37:24 +0200 Subject: [PATCH] Task1 was ended --- TaskA01/Task1.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 TaskA01/Task1.py diff --git a/TaskA01/Task1.py b/TaskA01/Task1.py new file mode 100644 index 0000000..eb8818c --- /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')