Computer Science
Write a program 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.
Python
Python String Manipulation
4 Likes
Answer
sentence = input("Enter a sentence: ")
modified_sentence = sentence.replace(' ', '-')
print(modified_sentence)
Output
Enter a sentence: Innovation drives progress
Innovation-drives-progress
Answered By
2 Likes
Related Questions
Input the string 'My School'. Write a script to partition the string at the occurrence of letter 'h'.
Write a program to convert a string with more than one word into titlecase string where string is passed as parameter. (Titlecase means that the first letter of each word is capitalized.)
Write a script to partition the string 'INSTITUTE' at the occurrence of letter 'T'.
What will be the output of the following programming code?
str = "My Python Programming" print (str[-5:-1]) print (str[1:5]) print (str[:-4]) print (str[0:]) print (str[:13-4]) print (str[:3])