Replace the Characters within a string.

Let’s say you are asked to create a string from the given input wherein you need to replace the occurences of first character from the input word. e.g. Input: Advanced — output: Adv#nced

# APPROACH 1:

string=input()       
res = ''    
chr=string[0]
count=0

for i in string:

    if i==chr:
        count+=1
        if count>1:
            i="#"
            res+=i
        else:
            res+=i
    else:
        res+=i
print(res)    

    

By Pankaj

Leave a Reply

Your email address will not be published. Required fields are marked *