CBSE Class 11 Computer Science
Question 15 of 19
Strings in Python — Question 14
Back to all questions 14
Question 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.
sentence = input("Enter a sentence: ")
modified_sentence = sentence.replace(' ', '-')
print(modified_sentence)Enter a sentence: Innovation drives progress
Innovation-drives-progress
sentence
=
input
(
"Enter a sentence: "
)
modified_sentence
=
sentence
.
replace
(
' '
,
'-'
)
print
(
modified_sentence
)
Output
Enter a sentence: Innovation drives progress
Innovation-drives-progress