-2

I looked it up and I have to use it like this:

letter = input ("Enter  a letter: ")
if letter == "a" or letter  == "e" or letter == "i" or letter  == "o" or letter == "u":
print ("It's  a vowel.")

But why I can I not use it like this? When I do this, and enter "a", nothing gets printed. I can do this with numbers.

vowel = ["a", "e", "i", "o", "u"]

userinput = str(input("Enter a letter of the alphabet: "))

if userinput == vowel:
    print("You have entered a vowel")


                                                 
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Modo
  • 7
  • 1
  • 4

1 Answers1

2

I believe what your looking for is this :

vowel = ["a", "e", "i", "o", "u"]

userinput = str(input("Enter a letter of the alphabet: ").lower())

if userinput in vowel:
    print("You have entered a vowel")
else:
    print('not a vowel')

Reason why code didn't work: Since vowel is a list, you need to use the statement if userinput in vowel rather than if userinput == vowel:

tyzion
  • 260
  • 1
  • 10
  • Oh wow, thank you! So the problem was I had not entered the "else" statement? – Modo Oct 12 '21 at 19:08
  • No , the problem was : Since vowel is a list, you need to use the statement `if userinput in vowel` rather than `if userinput == vowel:` – tyzion Oct 12 '21 at 19:10
  • question more to the OP - what happens if user enters an `A`? – rv.kvetch Oct 12 '21 at 19:11
  • Ok. I have never used the "in" before. Thank you. – Modo Oct 12 '21 at 19:11
  • 1
    @rv.kvetch edited the ans, by adding .lower() function, using it we can solve the issue of capital letters, btw Modo can you accept the ans, thank you – tyzion Oct 12 '21 at 19:13
  • @tyzion well I wanted to clarify with the OP first about how he'd expect to handle that scenario, however it's great that you were thinking ahead of me ;) – rv.kvetch Oct 12 '21 at 19:15
  • 1
    @rv.kvetch I didn't know. The .lower() is also something new I learned. Also, it tells me that is a consonant if I enter a number even though I have put in str. I thought it would be restricted to letters only. – Modo Oct 12 '21 at 19:22