Skip to content

Python-home-challenge#01-MaorWeiss #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Python-Home-Challenges/Challenge_01.txt
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
4 changes: 4 additions & 0 deletions Python-Home-Challenges/Creating_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Hi Hi Hello Hello Hi" > ~/PycharmProjects/file.txt
echo "File created succesfully"
39 changes: 39 additions & 0 deletions Python-Home-Challenges/Python-home-challenge#01-MaorWeiss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# HW03 - Open a text file and returns the most recurring word in that file.


def read_file():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to get better use of your function, file name should be an argument

with open('../file.txt', 'r') as tmp_file:
execute_file = tmp_file.readline()
return execute_file


def spilt_file(file):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var name file - you are not use file here, it is string, so var name might be misleading

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 #
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz fix indetation

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz add "if name" condition here

4 changes: 4 additions & 0 deletions Python-Home-Challenges/insructions_challenge#01.txt
Original file line number Diff line number Diff line change
@@ -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!