-1
myWord=input("Enter a Word: ")

if len(myWord) <= 3 :
    print(myWord)
elif myWord[-3:] == 'ing':
    print(myWord)
elif myWord[-1:] == 'a' or 'e' or 'i' or 'o' or 'u':
    newWord = myWord.replace('a' or 'e' or 'i' or 'o' or 'u', "ing")
    print(newWord)

I am working on a program that whenever I put input a word that is < than 3 words and ends with a vowel it will replace that vowel with "ing". The third "elif" statement is where I am having the most problems because whenever I run the program and type in a word that ends with a vowel it does not replace the vowel with "ing".

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
  • In addition `myWord.replace('a' or 'e' or 'i' or 'o' or 'u', "ing")` is used incorrectly. – DYZ Sep 14 '18 at 05:37
  • I apologize... I am fairly new to python, so what would you suggest I use instead? Am I using the "or" method incorrectly? – Shakespeareeee Sep 14 '18 at 05:40
  • replace function works with single characters, so you have to loop across all the vowels. `for v in ['a','e','i','o','u']: myWord.replace(v, 'ing')` – Raunaq Jain Sep 14 '18 at 05:41

1 Answers1

0

Welcome to stackoverflow, myWord[-1:] == 'a' or 'e' or 'i' or 'o' or 'u': does not what you thing it does, I'm afraid, it does not compare myword[-1] to those five things but does the comparision and then does if 'a' which is always true. Try

if myWord[-1:] in ['a', 'e', 'i', 'o', 'u']

Also in the last elif you should not use replace (and here also the or-structure is not correct), because it replaces all occurences of, not only the last one.

Bernhard
  • 1,253
  • 8
  • 18