-2
Word=input('please enter a word')
def cap(word):
      for char in word:
            if char in 'aeiou':
                  return letter.upper()

            else:
                  return letter

result=cap(word)
print result
Mark
  • 90,562
  • 7
  • 108
  • 148
Flahmez
  • 45
  • 1
  • 5

2 Answers2

3

You return immediately after examining the first character. Instead, you should go over all of them, and modify the ones you need.

def cap(word):
    result = ''
    for letter in word:
        if letter in 'aeiou':
            result += letter.upper()
        else:
            result += letter
    return result

Note, however, that this may be much easier to do with list comprehensions:

def cap(word):
    return ''.join(l.upper() if l in 'aeiou' else l for l in word)
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

In python you can have functions that continuously return values — they're called generators. You just use yield instead of return. You can then use them as iterators, or call list on them to get the values:

word=input('please enter a word')
def cap(word):
      for letter in word:
            if letter in 'aeiou':
                  yield letter.upper()

            else:
                  yield letter

result=cap(word)
print(''.join(list(result)))

However, if your goal is to translate a set of characters to another set of characters, there is a python string method for that: translate().

word=input('please enter a word')
upper_vowels = word.translate(str.maketrans('aeiou', 'AEIOU'))

print(upper_vowels)

This should be more efficient that looping and joining as well being easier to read. Also, you can save the translate table separately if you want to apply it to many strings.

Mark
  • 90,562
  • 7
  • 108
  • 148