Zed-King Institute

    Python Program to Check Vowel or Consonant

    easyif / elsePython

    A short program that shows how Python's in operator can replace a long chain of comparisons.

    The question

    Read one alphabet letter (it may be upper or lower case) and print Vowel or Consonant.

    The code

    program.py

    ch = input().strip()
    if ch.lower() in "aeiou":
        print("Vowel")
    else:
        print("Consonant")

    Input

    b

    Output

    Consonant

    How it works

    1. 1Read one character; .strip() removes any accidental spaces.
    2. 2.lower() turns A into a, so capital letters are handled too.
    3. 3ch in "aeiou" is True when the letter is one of the five vowels.

    Common mistakes

    • Writing if ch == 'a' or 'e' or 'i' — this is always True in Python and every letter becomes a vowel.
    • Forgetting upper case: without .lower(), E is reported as a consonant.

    Now solve a similar question yourself

    A new Python question every time, checked instantly.

    Practice questions

    More in if / else