π Features of String Analyzer
- Count total characters
- Count vowels & consonants
- Count digits & special characters
- Count words
- Reverse the string
- Check palindrome
- Find frequency of each character
π§Ύ Input Example
Enter string: Hello World 123!
π§ Logic Flow (Traditional Thinking)
Input β Loop β Condition β Count β Output
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)
π€ 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}
Top comments (0)