From 808a602df8c03b1bc510ba130b5776da641592c8 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 29 Nov 2019 13:48:53 +0200 Subject: [PATCH 1/4] Python-Home-Challenges-Maor Weiss --- Python-Home-Challenges/Creating_file.sh | 3 +++ .../Python-home-challenge#01-MaorWeiss.py | 27 +++++++++++++++++++ .../insructions_challenge#01.txt | 4 +++ 3 files changed, 34 insertions(+) create mode 100755 Python-Home-Challenges/Creating_file.sh create mode 100644 Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py create mode 100644 Python-Home-Challenges/insructions_challenge#01.txt diff --git a/Python-Home-Challenges/Creating_file.sh b/Python-Home-Challenges/Creating_file.sh new file mode 100755 index 0000000..81ad468 --- /dev/null +++ b/Python-Home-Challenges/Creating_file.sh @@ -0,0 +1,3 @@ +cd / +echo "please do not do what ever you want to do" > file.txt + diff --git a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py new file mode 100644 index 0000000..df08cdf --- /dev/null +++ b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py @@ -0,0 +1,27 @@ +# HW03 - Open a text file and returns the most recurring word in that file. + +fp = open('/file.txt', 'r') +# Open file # +f = fp.readline() +# Read file # +split_words_from_file = f.split() + +the_most_recurring_word = '' +biggest_counting = 0 +count = 0 + +copy_list = split_words_from_file +for list_arg in copy_list: + for word in split_words_from_file: + if list_arg == word: + count += 1 + if count > biggest_counting: + the_most_recurring_word = list_arg + biggest_counting = count + count = 0 + else: + count = 0 + +print 'The word "{}" which has appeared {} times is the most recurring word in the file.'.format(the_most_recurring_word, biggest_counting) +fp.close() +# Close file # diff --git a/Python-Home-Challenges/insructions_challenge#01.txt b/Python-Home-Challenges/insructions_challenge#01.txt new file mode 100644 index 0000000..5fd291c --- /dev/null +++ b/Python-Home-Challenges/insructions_challenge#01.txt @@ -0,0 +1,4 @@ +1. Open the "Creating_file.sh" file +2. execute the "Python-home-challenge#01-MaorWeiss.py" file + +Have a nice day! From b879bfd2b0cf420620183532b5db804da2a7e082 Mon Sep 17 00:00:00 2001 From: Maor Weiss Date: Sun, 1 Dec 2019 00:16:15 +0200 Subject: [PATCH 2/4] Change files after instructions and after Flake6 validation --- Python-Home-Challenges/Creating_file.sh | 2 +- .../Python-home-challenge#01-MaorWeiss.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Python-Home-Challenges/Creating_file.sh b/Python-Home-Challenges/Creating_file.sh index 81ad468..0236905 100755 --- a/Python-Home-Challenges/Creating_file.sh +++ b/Python-Home-Challenges/Creating_file.sh @@ -1,3 +1,3 @@ -cd / +cd /home/$USER/ echo "please do not do what ever you want to do" > file.txt diff --git a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py index df08cdf..0c215d4 100644 --- a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py +++ b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py @@ -8,19 +8,17 @@ the_most_recurring_word = '' biggest_counting = 0 -count = 0 copy_list = split_words_from_file for list_arg in copy_list: for word in split_words_from_file: + count = 0 if list_arg == word: count += 1 if count > biggest_counting: the_most_recurring_word = list_arg biggest_counting = count - count = 0 - else: - count = 0 + print 'The word "{}" which has appeared {} times is the most recurring word in the file.'.format(the_most_recurring_word, biggest_counting) fp.close() From d5d833fab1b980035e06e746a85693719e2a94bf Mon Sep 17 00:00:00 2001 From: Maor Weiss Date: Sun, 1 Dec 2019 14:14:30 +0200 Subject: [PATCH 3/4] Rewrite the 'Python-home-challenge#01-MaorWeiss.py' code --- Python-Home-Challenges/Challenge_01.txt | 2 +- .../Python-home-challenge#01-MaorWeiss.py | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Python-Home-Challenges/Challenge_01.txt b/Python-Home-Challenges/Challenge_01.txt index dcf4641..0818234 100644 --- a/Python-Home-Challenges/Challenge_01.txt +++ b/Python-Home-Challenges/Challenge_01.txt @@ -1,4 +1,4 @@ -Create a python progarm that do the following: +Create a python progarm that do the following: 1. Reads a text file 2. Returns the most recurring word in that file. diff --git a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py index 0c215d4..585e7c6 100644 --- a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py +++ b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py @@ -1,18 +1,16 @@ # HW03 - Open a text file and returns the most recurring word in that file. -fp = open('/file.txt', 'r') -# Open file # -f = fp.readline() +with open(r'/home/$USER/', 'r') as fp: + f = fp.readline() # Read file # split_words_from_file = f.split() -the_most_recurring_word = '' +# Creating variable for keeping the recurring value from the file # biggest_counting = 0 -copy_list = split_words_from_file -for list_arg in copy_list: +for list_arg in split_words_from_file: + count = 0 for word in split_words_from_file: - count = 0 if list_arg == word: count += 1 if count > biggest_counting: @@ -20,6 +18,5 @@ biggest_counting = count -print 'The word "{}" which has appeared {} times is the most recurring word in the file.'.format(the_most_recurring_word, biggest_counting) -fp.close() -# Close file # +print(f"The most recurring word in the file is '{the_most_recurring_word}'") +print(f"which has appeared {biggest_counting} times.") From 73dfa119f2d2d92a0d24447ea1c39b33f05f3f39 Mon Sep 17 00:00:00 2001 From: Maor Weiss Date: Sun, 1 Dec 2019 17:08:36 +0200 Subject: [PATCH 4/4] Changing note in line 8 --- Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py index 585e7c6..20c6541 100644 --- a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py +++ b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py @@ -5,7 +5,7 @@ # Read file # split_words_from_file = f.split() -# Creating variable for keeping the recurring value from the file # +# Creating variable for checking what is the recurring value # biggest_counting = 0 for list_arg in split_words_from_file: