From 808a602df8c03b1bc510ba130b5776da641592c8 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 29 Nov 2019 13:48:53 +0200 Subject: [PATCH 1/6] 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/6] 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/6] 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/6] 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: From d06953754cba16d65cbe8cb58df2f6aa27f1bca7 Mon Sep 17 00:00:00 2001 From: Maor Weiss Date: Mon, 2 Dec 2019 20:33:22 +0200 Subject: [PATCH 5/6] Changing py code by instructions #01 --- .../Python-home-challenge#01-MaorWeiss.py | 57 ++++++++++++------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py index 20c6541..08f8b63 100644 --- a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py +++ b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py @@ -1,22 +1,39 @@ # HW03 - Open a text file and returns the most recurring word in that file. -with open(r'/home/$USER/', 'r') as fp: - f = fp.readline() -# Read file # -split_words_from_file = f.split() - -# Creating variable for checking what is the recurring value # -biggest_counting = 0 - -for list_arg in split_words_from_file: - count = 0 - 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 - - -print(f"The most recurring word in the file is '{the_most_recurring_word}'") -print(f"which has appeared {biggest_counting} times.") + +def read_file(): + with open('/home/$USER/, 'r') as tmp_file: + execute_file = tmp_file.readline() + return execute_file + + +def spilt_file(file): + split_words_from_file = file.split() + return split_words_from_file + + +def printing_the_recurring_word(split_words_from_file): + biggest_counting = 0 +# Creating variable for keeping the recurring value from the file # + words = dict() + for list_arg in split_words_from_file: + if list_arg in words: + words[list_arg] = words[list_arg] + 1 + else: + words[list_arg] = 1 + + for key in words: + if words[key] > biggest_counting: + biggest_counting = words[key] + the_most_recurring_word = key + print(f"The most recurring word in the file is '{the_most_recurring_word}'") + print(f"which has appeared {biggest_counting} times.") + + +def main(): + my_file = read_file() + my_split_file = spilt_file(my_file) + printing_the_recurring_word(my_split_file) + + +main() From 812b5c4fa1a88e81c42b213fb2acd1d4d5e77061 Mon Sep 17 00:00:00 2001 From: Maor Weiss Date: Tue, 3 Dec 2019 15:25:46 +0200 Subject: [PATCH 6/6] Changing direction isuues --- Python-Home-Challenges/Creating_file.sh | 5 +++-- Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Python-Home-Challenges/Creating_file.sh b/Python-Home-Challenges/Creating_file.sh index 0236905..3c3659e 100755 --- a/Python-Home-Challenges/Creating_file.sh +++ b/Python-Home-Challenges/Creating_file.sh @@ -1,3 +1,4 @@ -cd /home/$USER/ -echo "please do not do what ever you want to do" > file.txt +#!/bin/bash +echo "Hi Hi Hello Hello Hi" > ~/PycharmProjects/file.txt +echo "File created succesfully" diff --git a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py index 08f8b63..f819cd3 100644 --- a/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py +++ b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py @@ -2,7 +2,7 @@ def read_file(): - with open('/home/$USER/, 'r') as tmp_file: + with open('../file.txt', 'r') as tmp_file: execute_file = tmp_file.readline() return execute_file @@ -26,7 +26,7 @@ def printing_the_recurring_word(split_words_from_file): if words[key] > biggest_counting: biggest_counting = words[key] the_most_recurring_word = key - print(f"The most recurring word in the file is '{the_most_recurring_word}'") + print(f"The most recurring word: '{the_most_recurring_word}'") print(f"which has appeared {biggest_counting} times.")