Answer to Question #250212 in Python for binnu

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




1
Expert's answer
2021-10-12T07:40:14-0400
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")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS