Type a word and return the word with uppercase vowels

Asked

Viewed 204 times

3

vogais = 'a, e, i, o, u'
palavra = str(input('Digite uma palavra: '))
if palavra.upper() in vogais:
    print(palavra)
else:
    palavra

Well, I did so but it didn’t work. I can’t do the program compare and recognize only the vowels of the word and return only with the uppercase vowels.

  • If it’s a challenge in English, be sure to include the y on vowels.

1 answer

4


This code does not make much sense, is all "run over". It starts with a problem that does not cause error. Why transform a string in string?

Why separate the comma vowels if you only need to put the vowels to check if the letter is there?

If the problem asks to check if the letter is vowel because the test is done over the whole word? And because it converts the whole word to uppercase and then sees if it’s between the vowels. Between vowels only, between vowels, the comma or blank space. And it’s never going to be for two reasons: you turn it to uppercase and then you look where it’s just lowercase, it can’t work. But it’s worse because it’s asking to see if the whole word is between the vowels, clear that a word is not unless the word is just a vowel, or a sequence that is there.

So you need to sweep the word by taking letter and testing whether the letter, not the word, is between the vowels, and only the vowels, nothing else. If it is, there you print with upper(), or otherwise should print also without changing the letter, can not just play the variable there without saying what to do with it.

The way it is will put a letter in each line, I would need to format to not skip line, but I leave this as a final exercise because it does not make clear if you need to put everything in the same line.

There are other, simpler ways to do this, but for starters I think it’s good:

vogais = 'aeiou'
palavra = input('Digite uma palavra: ')
for letra in palavra:
    if letra in vogais:
        print(letra.upper())
    else:
        print(letra)

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

  • Thank you! For the explanation, it worked, this one I tried in several ways to do it but could not!

  • @Uberlantorres see on [tour] the best way to say thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.