Remove Consonants
Remove consonants while keeping English vowels and nonletters. Students trace an or condition and avoid confusing consonant deletion with keeping vowels only.
1# Take string input2s = input("Enter a string: ")34# Remove consonants5vowels = "aeiouAEIOU"6result = ""7for char in s:8 if char in vowels or not char.isalpha():9 result += char1011print(f"Without consonants: {result}")
Output
Enter a string: Hello World Without consonants: eo o
In this one
- Combine preservation alternatives
- Retain nonletters
- Apply an English-vowel policy
How it works
- 1
Visit every source character.
- 2
Keep listed vowels or nonalphabetic characters.
- 3
Print the resulting text after other letters are omitted.
Edge cases
Do digits survive?
Do digits survive?
Yes. They are nonalphabetic.
Does B survive?
Does B survive?
No. It is alphabetic but not a listed vowel.
What's going on
A character is kept when it is a listed vowel or not alphabetic. The second part preserves spaces, digits, and punctuation.
For Hello 2!, the result retains eo 2!. Alphabetic characters outside the listed English vowels are removed under this rule, so Unicode vowel classification is limited. The loop builds new text and leaves the original response unchanged.
Do digits survive? Yes. They are nonalphabetic.
Does B survive? No. It is alphabetic but not a listed vowel.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Why use or?
Pick an answer to check it.
Question 2
Do digits survive?
Pick an answer to check it.
Questions people ask
Do digits survive?
Yes. They are nonalphabetic.
Does B survive?
No. It is alphabetic but not a listed vowel.
Why use or?
Either listed-vowel status or nonletter status is enough.
๐Related Content
- ๐
Phase 5 - Learn Concepts
Review Phase 5 concepts and explanations
- ๐
Phase 5 - Quiz
Test your Phase 5 understanding with quiz questions
- ๐ป
Phase 5 - All Practice Problems
Explore all practice problems for Phase 5
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum