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.
Any help is appreciated. Thank you
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#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 = 0 |
User has been warned for this post. Reason: Not posting code in code tags