Westonci.ca offers fast, accurate answers to your questions. Join our community and get the insights you need now. Join our platform to get reliable answers to your questions from a knowledgeable community of experts. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.
Sagot :
Answer:
In Python:
toreplace = input("Word and replacement: ")
sentence = input("Sentence: ")
wordsplit = toreplace.split(" ")
for i in range(0,len(wordsplit),2):
sentence = sentence.replace(wordsplit[i], wordsplit[i+1])
print(sentence)
Explanation:
This gets each word and replacement from the user
toreplace = input("Word and replacement: ")
This gets the sentence from the user
sentence = input("Sentence: ")
This splits the word and replacement using split()
wordsplit = toreplace.split(" ")
This iterates through the split words
for i in range(0,len(wordsplit),2):
Each word is then replaced by its replacement in the sentence
sentence = sentence.replace(wordsplit[i], wordsplit[i+1])
This prints the new sentence
print(sentence)
We appreciate your visit. Hopefully, the answers you found were beneficial. Don't hesitate to come back for more information. We appreciate your time. Please come back anytime for the latest information and answers to your questions. Thank you for visiting Westonci.ca, your go-to source for reliable answers. Come back soon for more expert insights.