0% found this document useful (0 votes)
3 views1 page

Python Word Counter Program

The document describes a Python program that analyzes text input by counting the total number of words, the number of unique words, and the frequency of each word. It processes the input by converting it to lowercase, removing punctuation, and splitting it into words. The results are then displayed to the user.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Python Word Counter Program

The document describes a Python program that analyzes text input by counting the total number of words, the number of unique words, and the frequency of each word. It processes the input by converting it to lowercase, removing punctuation, and splitting it into words. The results are then displayed to the user.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#Assignment no.

02
#Aleeshba Siddique,FA24-BMD-015
#Python Code
#The program takes a sentence or a paragraph as input from the user.
#it then counts and displays: total number of words, number of unique
#words,and frequency of each word in text.
#Word Counter Analyzer

# Take input from user


text = input("Enter a sentence or paragraph: ")

# Convert to lowercase for accurate counting


text = [Link]()

# Remove punctuation
import string
for char in [Link]:
text = [Link](char, "")

# Split text into words


words = [Link]()

# Count total words


total_words = len(words)

# Count unique words


unique_words = set(words)
num_unique = len(unique_words)

# Count frequency of each word


word_frequency = {}
for word in words:
word_frequency[word] = word_frequency.get(word, 0) + 1

# Display results
print("\n--- Word Analysis ---")
print(f"Total number of words: {total_words}")
print(f"Number of unique words: {num_unique}")
print("\nWord Frequency:")
for word, count in word_frequency.items():
print(f"{word}: {count}")

You might also like