Please write a function three(string) that return a string that all three-letter words are replaced by ***.
For example:
three("submit only one question per post. ") return: "submit only *** question *** post. "
Please using Python!
Python code:
#defining three function
def three(string):
#splitting it into words list
string=string.split()
#looping each word
for i in range(len(string)):
#checking if its length
is 3
if(len(string[i])==3):
#replacing it with ***
string[i]="***"
#converting it back to string
return " ".join(string)
#calling three function for a sample value and printing
result
print(three("submit only one question per post."))
Screenshot:
Output:
Get Answers For Free
Most questions answered within 1 hours.