1

I was doing some exercises to train python and improve, etc. And then i got one that asked me to develop a program that read a letter and print if it is a vowel or a consonant.

if(letter== 'a' or letter == 'A' or letter == 'e' or letter == 'E' or letter == 'i' or letter == 'I' or letter == 'o' or letter == 'O' or letter == 'u' or letter == 'U'):
    print(f"{letter} it's a vow.")
elif((letter.isalpha()) == False):
    print('I said letter, not numbers')
else:
    print(f'{letter} it's a consonant.')

Anyway, this got really bigger than i wanted and it's really ugly also it's a pain in the ass type all those letters. I want to know if there's a way to detect if it's a vow or a consonant with python, importing or not a package to do that. Tried searching only but couldn't find anything.

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76
arkashdev
  • 23
  • 3

1 Answers1

3

You can use the str.lower (or str.upper) method and the str in str operator:

# or, if letter.upper() in 'AEIOU':
if letter.lower() in 'aeiou':
    print(f"{letter} it's a vow.")
elif not letter.isalpha():
    print("I said letter, not numbers")
else:
    print(f"{letter} it's a consonant.")
DjaouadNM
  • 22,013
  • 4
  • 33
  • 55