Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Remove Consonants

Remove consonants while keeping English vowels and nonletters. Students trace an or condition and avoid confusing consonant deletion with keeping vowels only.

IntermediatePhase 5 - Category 2: Character OperationsExample 10 of 10
remove-consonants.py
1# Take string input
2s = input("Enter a string: ")
3
4# Remove consonants
5vowels = "aeiouAEIOU"
6result = ""
7for char in s:
8 if char in vowels or not char.isalpha():
9 result += char
10
11print(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. 1

    Visit every source character.

  2. 2

    Keep listed vowels or nonalphabetic characters.

  3. 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.