Question #250212

Write a function that takes an input parameter as a String. The function should replace the alternate words in it with “xyz” and print it. Words are separated by dots. (Avoid using inbuilt functions)


If input is “i.like.this.program.very.much”

Output will be “i.xyz.this.xyz.very.xyz




Expert's answer

def replace(str1):
    str2 = list(str1.split('.'))
    l = len(str2)
    string = " "
    string += str2[0] +"."
    for i in range(1, l):
        
        if(i % 2 !=0):
            string += "xyz"+"."
        else:
            string += str2[i]+"."
    print(string)
replace("i.like.this.program.very.much")
LATEST TUTORIALS
APPROVED BY CLIENTS