0

I'm trying to create a program that you can type a word and will tell you the vowels and consonants on it, I tried to use a list for the vowels but when I run the program it only prints the else or consonant parameter.I'm new at python-3.x and programming in general. What am I doing wrong?.

def run(word,list_vocal):
    for letter in word:
        if letter == list_vocal:
           print(letter + 'is a vowel')
        else:
           print(letter + 'is a consonant')
if __name__ == '__main__':
   word = str(input('Type your word ')
   list_vocal = ['a', 'e' , 'i', 'o'. 'u']
   run(word,list_vocal)

I'm only considering the Spanish vowels.

Here's the output.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • 4
    `if letter == list_vocal:` - if you read this as _if letter is list_vocal_, do you see the mistake? – Nelewout Apr 20 '20 at 18:29
  • typo `list_vocal = ['a', 'e' , 'i', 'o'. 'u']` in your list. its a `.` instead of `,` => `SyntaxError: invalid syntax`. Beside that: no letter will be equal to a list. – Patrick Artner Apr 20 '20 at 18:39
  • https://stackoverflow.com/questions/7571635/fastest-way-to-check-if-a-value-exists-in-a-list – Patrick Artner Apr 20 '20 at 18:43

1 Answers1

1

You are checking if a string is equal to a list which will never be true.

Instead check if it is in the list:

def run(word,list_vocal):
    for letter in word:
        if letter in list_vocal:
           print(letter + 'is a vowel')
        else:
           print(letter + 'is a consonant')
if __name__ == '__main__':
   word = str(input('Type your word ')
   list_vocal = ['a', 'e' , 'i', 'o', 'u']
   run(word,list_vocal)
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
Ryan Schaefer
  • 3,047
  • 1
  • 26
  • 46