Q. Write a function that takes a sentence as an input parameter where each word in the sentence is separated by a space. The function should replace each blank with a hyphen and then return the modified sentence.


Answer :-


def path( string ):
    newsen = ""
    for i in string :
        if i.isspace():
            newsen += "-"
        else :
            newsen += i
    return newsen

sen = input("Enter a Sentance :-")
print("New String :-", path(sen) )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post