Skip to content

Commit

Permalink
added a file without license
Browse files Browse the repository at this point in the history
  • Loading branch information
suchetla committed Jul 17, 2024
1 parent 6b5090d commit f259306
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import re
from collections import Counter

def clean_text(text):
text = text.lower()
text = re.sub(r'[^a-z\s]', '', text)
return text

def count_words(text):
words = text.split()
return len(words)

def word_frequency(text):
words = text.split()
frequency = Counter(words)
return frequency

def most_common_word(text):
frequency = word_frequency(text)
most_common = frequency.most_common(1)
return most_common[0] if most_common else None

def main():
text = input("Enter a paragraph of text: ")

cleaned_text = clean_text(text)
word_count = count_words(cleaned_text)
frequency = word_frequency(cleaned_text)
common_word = most_common_word(cleaned_text)

print(f"\nTotal number of words: {word_count}")
print("\nWord frequencies:")
for word, count in frequency.items():
print(f"{word}: {count}")

if common_word:
print(f"\nMost common word: '{common_word[0]}' with {common_word[1]} occurrences.")
else:
print("\nNo words found.")

if __name__ == "__main__":
main()

0 comments on commit f259306

Please sign in to comment.