Sunday, 19 April 2026

πŸš€ Day 24/150 – Check Vowel or Consonant in Python

 

πŸš€ Day 24/150 – Check Vowel or Consonant in Python

One of the simplest and most important beginner problems in Python is checking whether a character is a vowel or a consonant. It helps you understand conditions, strings, and user input.


πŸ“Œ What is a Vowel?

Vowels in English are:

a, e, i, o, u

(Also consider uppercase: A, E, I, O, U)

Everything else (alphabets) is a consonant.

πŸ”Ή Method 1 – Using if-else

char = 'a' if char.lower() in 'aeiou': print("Vowel") else: print("Consonant")








🧠 Explanation:
  • char.lower() converts input to lowercase.
  • 'aeiou' contains all vowels.
  • in checks if the character exists in that string.

πŸ‘‰ Best for: Clean and readable logic.

πŸ”Ή Method 2 – Taking User Input

char = input("Enter a character: ") if char.lower() in 'aeiou': print("Vowel") else: print("Consonant")








🧠 Explanation:
  • Takes input from user.
  • Works for both uppercase and lowercase.

πŸ‘‰ Best for: Interactive programs.

πŸ”Ή Method 3 – Using Function

def check_vowel(char): if char.lower() in 'aeiou': return "Vowel" else: return "Consonant" print(check_vowel('e'))








🧠 Explanation:
  • Function makes code reusable.
  • Returns result instead of printing directly.

πŸ‘‰ Best for: Structured programs.

πŸ”Ή Method 4 – Using Lambda Function

check = lambda c: "Vowel" if c.lower() in 'aeiou' else "Consonant" print(check('b'))




🧠 Explanation:

  • Short one-line function.
  • Uses inline if-else.

πŸ‘‰ Best for: Quick checks.

⚡ Key Takeaways

  • Use in keyword for easy checking
  • Convert to lowercase using .lower()
  • Always validate user input
  • Vowels = aeiou

πŸ’‘ Pro Tip

Try extending this:

  • Count vowels in a string
  • Check vowels in a sentence
  • Build a mini text analyzer
Keep going πŸš€

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (245) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (29) Azure (10) BI (10) Books (262) Bootcamp (6) C (78) C# (12) C++ (83) Course (87) Coursera (300) Cybersecurity (30) data (5) Data Analysis (31) Data Analytics (22) data management (15) Data Science (344) Data Strucures (17) Deep Learning (152) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (19) Finance (10) flask (4) flutter (1) FPL (17) Generative AI (70) Git (10) Google (51) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (42) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (285) Meta (24) MICHIGAN (5) microsoft (11) Nvidia (8) Pandas (14) PHP (20) Projects (32) pytho (1) Python (1308) Python Coding Challenge (1128) Python Mistakes (51) Python Quiz (476) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (49) Udemy (18) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)