# bellow are programs to replace the letter "e" with "z" and vowels with "z" respectively. The first one is my original attempt which # overcomplicated things by using the find() function. All that is need is to you an if/else statement with concatination as shown in # in the second example. string = "abcdefghijklmnopqrstuvwxyz" newString = "" for i in string: pos = string.find("e") if pos == -1: newString = newString + string break newString = newString + string[:pos] + "z" string = string[pos+1:] print newString string = "abcdefghijklmnopqrstuvwxyz" newString1 = "" for i in string: if i == "e" or i == "a" or i == "i" or i == "u" or i == "o": newString1 = newString1 + "z" else: newString1 = newString1 + i print newString1 print "Done"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question