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..3c3659e --- /dev/null +++ b/Python-Home-Challenges/Creating_file.sh @@ -0,0 +1,4 @@ +#!/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 new file mode 100644 index 0000000..f819cd3 --- /dev/null +++ b/Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py @@ -0,0 +1,39 @@ +# HW03 - Open a text file and returns the most recurring word in that file. + + +def read_file(): + with open('../file.txt', '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: '{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() 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!