-
Notifications
You must be signed in to change notification settings - Fork 0
/
censor.py
30 lines (22 loc) · 894 Bytes
/
censor.py
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
28
29
30
def main():
# Prompt the user to input text they want to censor.
text = input("Enter the text you want to censor: ").split()
# Prompt the user to input words in the format "apple, car,.." that they want to censor.
words = input(
"Enter words in the format 'apple, car,..' that you want to censor: "
).split(", ")
# Censor the text and print the result.
censored_text = censor(text, words)
print(censored_text)
def censor(text, words):
censored_text = ""
for word in text:
if word in words:
# If the word is in the list of words to censor, replace it with asterisks of the same length.
censored_text += len(word) * "*" + " "
else:
# If the word is not in the list, keep it unchanged.
censored_text += word + " "
return censored_text
if __name__ == "__main__":
main()