Home > Software design >  In python, how do I search for character before and if it is that character it changes to something
In python, how do I search for character before and if it is that character it changes to something

Time:10-07

Enter a word: IWA is pronounced Ee-wah

expected output = Ee-vah

I need to know the statement when there is an 'i' or 'e' and if there is and word after would change from 'w' to 'v'

CodePudding user response:

use loop & if statement

...
string = input()

for i in range(len(string)):
    if string[i] == "w":
        string[i] = "v"
    ...

CodePudding user response:

That's no dificult. You can use function replace() . Let's see the code :

stack="There is vwa"

if stack.find("e") or stack.find("i"):
    stack.replace("w","v")

print(stack)

That's it. Everthing in python is object. You can use pycharm to look for functions after dot too if you prefer.

  • Related