-4

I would like to write a program that asks the user for a word and only returns the constants. But I am stuck with this program, I would expect this program to do what I have mentioned above, but all it does is returns the word row by row.

original = input('Enter a word:')
word = original.lower()
first = word[0]
second = word[1]
third = word[2]
fourth = word[3]
fifth=word[4]


if first == "a" or "e" or "i" or "u":
    print (first)
else:
    print ("")
if second == "a" or "e" or "i" or "u":
    print (second)
else:
    print ("")
if third == "a" or "e" or "i" or "u":
    print (third)
else:
    print ("")
if fourth == "a" or "e" or "i" or "u":
    print (fourth)
else:
    print ("")
if fifth == "a" or "e" or "i" or "u":
    print (fifth)
else:
    print ("")

2 Answers2

1

Strip all the vowels from a word and print it:

original = input('Enter a word:')
print("".join(x for x in original if x.lower() not in "aeiou"))
Maxime Chéramy
  • 17,761
  • 8
  • 54
  • 75
0

The precedence is wrong. "or" has higher precedence then "==" - see https://docs.python.org/2/reference/expressions.html#operator-precedence

So the line:

if first == "a" or "e" or "i" or "u":

Is the same as:

if (first == "a") or ("e") or ("i") or ("u"):

Which I suspect isn't what you wanted. The following might work better:

if first in "aeiu":

However also note this is case sensitive...

Penguin Brian
  • 1,991
  • 14
  • 25