Question

Please write a function three(string) that return a string that all three-letter words are replaced by...

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!

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a recursive function block_count(string) to return the number of blocks consisting of the same letter...
Write a recursive function block_count(string) to return the number of blocks consisting of the same letter in the given input string. Example. >>> block_count ('AABBCCBBDDD') 5 >>>block_count ('GGABAA') 4
write a function call character_thing (string, character) that takes in a string and a character. The...
write a function call character_thing (string, character) that takes in a string and a character. The function will return the number of times the character appears in the string. please be in python
4. Create a function, which takes as input a string and a letter. Determine whether or...
4. Create a function, which takes as input a string and a letter. Determine whether or not the letter is present in the string. The function should return a logical true/false if the given letter is present/absent. HINT: use find and isempty. Please anyone helping me with this question can you code using Matlab software, please.
1.Write a function which takes a string that contains two words separated by any amount of...
1.Write a function which takes a string that contains two words separated by any amount of whitespace, and returns a string in which the words are swapped around and the whitespace is preserved. Hint: use regular expressions where \s detects the whitespaces in a string. Example: given "Hello     World", return "World         Hello" 2.Pandas exercises: Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. Write a python program using Pandas to...
Write a python function called unique words that takes a phrase as an input string and...
Write a python function called unique words that takes a phrase as an input string and returns a list of the unique words found in that phrase. The words should be listed in alphabetical order.
Write a function named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "i" replaced with the character "n python
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report the total number of words (as an integer) and the average word length (as an un-rounded number). For example, suppose the file tobe.txt contains the following text: To be or not to be, that is the...
Please code in Java Write a recursive method that takes a string and return a string...
Please code in Java Write a recursive method that takes a string and return a string where every character appears twice. For example, if the string is “HELLO”, it will return “HHEELLOO”. Write a program to test it.
solve in python 3.8 please The question is about Strings Modify your function so that it...
solve in python 3.8 please The question is about Strings Modify your function so that it can handle the following two situations: The string given as an argument has no characters. In this case, you should return the empty string. The string given as an argument has one character. In this case, you should return the one-character string given to you. Without any consideration for these cases, your function probably causes an error or returns the wrong result in the...
Create program that sorts words of a string based on first letter of each word. Use...
Create program that sorts words of a string based on first letter of each word. Use C programming language. - Only use stdio.h and string.h - Remove any newline \n from input string - Use insert function - Input prompt should say "Enter string of your choice: " - Output should print sorted string on new line Example:     Enter string of your choice: this is a string     a is string this
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT