Oct-05-2016, 01:03 AM
I am making a program for my Introduction to Computer Science course where I have to type in a sentence: "Dr Mathias is completely full of shirt I wish that jumping papaya would eat some macaroni" and censor the words: "papaya, grasshopper, jumping, shirt, macaroni".
I was able to make a program that would censor words that were inputted, but I am not able to fix it to where it would automatically censor words that are put into a list, without having to input anything. This is where I have gotten so far, when I try to do it I am not getting any output.
I was able to make a program that would censor words that were inputted, but I am not able to fix it to where it would automatically censor words that are put into a list, without having to input anything. This is where I have gotten so far, when I try to do it I am not getting any output.
#program to censor a string #input sentence and which words to censor originalsentence = raw_input("Enter the text to censor: ") censoredwords = ["papaya","grasshopper","jumping","shirt","macaroni"] censor="" wordattempt=[] wordlist="".join(censoredwords) counter=0 #apply censor to words typed in for character1 in str(originalsentence): for character2 in censoredwords: if character1 == wordlist[counter]: wordattempt.append(character1) censor=censor+"*" counter=counter+1 #print censored version of word if "".join(wordattempt)==censoredwords and counter == len(censoredwords): print originalsentence.replace(censoredwords,censor) censor="" wordattempt=[] counter=0Any help is appreciated. Thank you