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/Creating_file.sh b/Python-Home-Challenges/Creating_file.sh new file mode 100755 index 0000000..0236905 --- /dev/null +++ b/Python-Home-Challenges/Creating_file.sh @@ -0,0 +1,3 @@ +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 new file mode 100644 index 0000000..20c6541 --- /dev/null +++ b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py @@ -0,0 +1,22 @@ +# 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.") 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!