Program Instructions
Write a program called censor.py. This program will have the following functionality and requirements:
if __name__ == "__main__": main()
Skeleton of needed code:
def main(): # Get input for the phrase/sentence # Get input for multiple words to replace print(replaceMultiWords(s, w)) def replaceMultiWords(sentence, words): # Split "words" by space # Loop through each words, and call replaceWord(s, w) # return sentence when done looping def replaceWord(sentence, word): # Replace word in sentence with equal amount of dashes # return sentence if __name__ == "__main__": main()
Program In Python :-
def main():
# Get input for the phrase/sentence
s = input("Input a sentence : ")
# Get input for multiple words to replace
w = input("Enter a list of words you want to replace (separated by spaces) : ")
print(replaceMultiWords(s, w))
def replaceMultiWords(sentence, words):
# Split "words" by space
lst = words.split(" ")
# Loop through each words, and call replaceWord(s, w)
for i in lst:
sentence = replaceWord(sentence,i)
# return sentence when done looping
return sentence
def replaceWord(sentence, word):
# Replace word in sentence with equal amount of dashes
l = len(word) #find the length of the word
dashes = '-' * l
sentence = sentence.replace(word,dashes)
# return sentence
return sentence
if __name__ == "__main__":
main()
Output:-
Get Answers For Free
Most questions answered within 1 hours.