Cannot determine vowels from consonants

前端 未结 5 1665
北恋
北恋 2021-01-07 00:28

With the code below, no matter what the first letter of the input is, it is always determined as a vowel:

original = raw_input(\"Please type in a word: \")
f         


        
5条回答
  •  攒了一身酷
    2021-01-07 00:46

    Python is not the English language. If you have a bunch of expressions with or or and between them, each one must make sense on its own. Note that on its own:

    if "e":
        print("something")
    

    will always print something, even if letter doesn't equal "e".

    You need to do it like this:

    if letter == "a" or letter == "e"  # (...)
    

    Or, more concisely:

    if letter in "aeiouy":
    

提交回复
热议问题