w3resource

Python Exercise: Check whether an alphabet is a vowel or consonant

Python Conditional: Exercise - 32 with Solution

Write a Python program to check whether an alphabet is a vowel or consonant.

Pictorial Presentation:

Python Exercise: Check whether an alphabet is a vowel or consonant

Sample Solution:

Python Code:

# Request input from the user to input a letter of the alphabet and assign it to the variable 'l'
l = input("Input a letter of the alphabet: ")

# Check if the input letter 'l' is present in the tuple containing vowels ('a', 'e', 'i', 'o', 'u')
if l in ('a', 'e', 'i', 'o', 'u'):
    print("%s is a vowel." % l)  # Display a message stating that the input letter is a vowel
# If the input letter is 'y', display a message stating that it sometimes represents a vowel and sometimes a consonant
elif l == 'y':
    print("Sometimes the letter y stands for a vowel, sometimes for a consonant.")
# If the input letter doesn't fall into any of the above conditions, it is considered a consonant; display a message stating so
else:
    print("%s is a consonant." % l) 
	 

Sample Output:

Input a letter of the alphabet: u                                                                             
u is a vowel. 

Flowchart:

Flowchart: Check whether an alphabet is vowel or consonant

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to calculate a dog's age in dog's years.
Next: Write a Python program to convert month name to a number of days.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/python-exercises/python-conditional-exercise-32.php