difficulty making vowels uppercase

Asked

Viewed 88 times

2

I was making a script and her goal was to get the characters to move forward.

But it was only the alphabetic characters that walked a position. And finally she should turn lowercase vowels into uppercase vowels.

Here is the code:

def LetterChanges(str):
    x = list(str)
    str = ''

    for i in range(len(x)):
        if x[i] == 'z':
            str += 'A'
            continue

        # testa para ver se faz parte do alfabeto
        if x[i].isalpha():
            # faz a letra andar uma posição
            str += chr(ord(x[i]) + 1)
        else:
            str += x[i]

    # Faz as vogais ficarem grandes
    str.replace('e','E')
    str.replace('i','I')
    str.replace('o','O')
    str.replace('u','U')

    return str

print(LetterChanges(input()))

The whole code works 100% only the part of the vowels that doesn’t work.

If anyone can help, thank you.

  • 2

    For future visitors, remember that you are overwriting the global function str() within its function LetterChanges. It would be better to choose another name for the function argument to not conflict with the built-in functions.

1 answer

8


Hugo, you need to take the return of the replace.

You did it this way:

str.replace('e','E')

But replace returns the changed value, so you need to assign the return to a variable:

str = str.replace('e','E')

By making this change, your code will work as you wish

Browser other questions tagged

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