DEV Community

Jyoti Jingar
Jyoti Jingar

Posted on

MINI PROJECT: String Analyzer

๐Ÿ“Œ Features of String Analyzer

  1. Count total characters
  2. Count vowels & consonants
  3. Count digits & special characters
  4. Count words
  5. Reverse the string
  6. Check palindrome
  7. Find frequency of each character

๐Ÿงพ Input Example

Enter string: Hello World 123!

Enter fullscreen mode Exit fullscreen mode

๐Ÿง  Logic Flow (Traditional Thinking)

Input โ†’ Loop โ†’ Condition โ†’ Count โ†’ Output

Enter fullscreen mode Exit fullscreen mode

Code (Complete)

s = input("Enter string: ")

vowels = 0
consonants = 0
digits = 0
spaces = 0
special = 0

for ch in s:
    if ch.lower() in "aeiou":
        vowels += 1
    elif ch.isalpha():
        consonants += 1
    elif ch.isdigit():
        digits += 1
    elif ch == " ":
        spaces += 1
    else:
        special += 1

# Word count
words = len(s.split())

# Reverse string
reverse_str = s[::-1]

# Palindrome check
if s.replace(" ", "").lower() == reverse_str.replace(" ", "").lower():
    palindrome = "Yes"
else:
    palindrome = "No"

# Character frequency
freq = {}
for ch in s:
    freq[ch] = freq.get(ch, 0) + 1

print("\n--- String Analysis Report ---")
print("Total characters:", len(s))
print("Words:", words)
print("Vowels:", vowels)
print("Consonants:", consonants)
print("Digits:", digits)
print("Spaces:", spaces)
print("Special characters:", special)
print("Reversed string:", reverse_str)
print("Palindrome:", palindrome)
print("Character Frequency:", freq)

Enter fullscreen mode Exit fullscreen mode

๐Ÿ“ค Output Example

Enter string: jyoti jingar

--- String Analysis Report ---
Total characters: 12
Words: 2
Vowels: 4
Consonants: 7
Digits: 0
Spaces: 1
Special characters: 0
Reversed string: ragnij itoyj
Palindrome: No
Character Frequency: {'j': 2, 'y': 1, 'o': 1, 't': 1, 'i': 2, ' ': 1, 'n': 1, 'g': 1, 'a': 1, 'r': 1} 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)