Share via

GIT and GIThub

Pallavi Darji 0 Reputation points
2026-03-26T05:49:10.8066667+00:00

"Write a Python program that counts the frequency of each word in a text file. Then, create a Git repository, add your Python file, commit it with a message, and push it to a new GitHub repository."

Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.

0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-26T05:49:23.0366667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Python program (save as word_count.py):

    from collections import Counter
    import re
    
    
    def count_word_frequency(file_path: str) -> None:
        with open(file_path, "r", encoding="utf-8") as f:
            text = f.read().lower()
    
        # Split on non‑alphabetic characters
        words = re.findall(r"[a-zA-Z']+", text)
        counts = Counter(words)
    
        for word, freq in counts.items():
            print(f"{word}: {freq}")
    
    
    if __name__ == "__main__":
        # Replace 'input.txt' with the path to the text file
        count_word_frequency("input.txt")
    

    Git and GitHub steps (command line workflow):

    1. In a terminal, go to the folder that contains word_count.py:
         cd path/to/your/project
      
    2. Initialize a local Git repository:
         git init
      
    3. Stage the Python file:
         git add word_count.py
      
    4. Commit with a message:
         git commit -m "Add word frequency counter script"
      
    5. In GitHub, create a new, empty repository (no README, license, or .gitignore) and copy its clone URL.
    6. Connect the local repo to the new GitHub repo and push:
         git remote add origin <clone URL>
         git push -u origin main
      

    After these steps, the Python program is tracked in Git and available in the new GitHub repository.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.