Skip to content

9 #20

Description

@legend17-dot

import string
def analyze_text(paragraph):

Convert to lowercase

text = paragraph.lower()

Count sentences

sentence_count = paragraph.count('.') + paragraph.count('!') + paragraph.count('?')

Remove punctuation for word analysis

for ch in string.punctuation:
text = text.replace(ch, "")
words = text.split()

Word frequency

freq = {}
for word in words:
if word in freq:
freq[word] += 1
else:
freq[word] = 1

Longest word

longest_word = max(words, key=len) if words else ""

Total words

total_words = len(words)

Display results

print("\n--- Text Analysis ---")
print("Total Words:", total_words)
print("Number of Sentences:", sentence_count)
print("Longest Word:", longest_word)
print("\nWord Frequency:")
for word in freq:
print(word, ":", freq[word])
paragraph = input("Enter a paragraph:\n")
analyze_text(paragraph) Page | 18
Pyt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions