Question
In Python
1 2 Write a function that removes all occurrences of a given letter from a string: test (remove_letter (a, apple) pple)
### Run the following lines. # If you get Correct you # did it right. if remove_letter(a, banana) == nn: print(Corre
0 0
Add a comment Improve this question Transcribed image text
Answer #1

# If you have a query/issue with respect to the answer, please drop a comment. I will surely try to address your query ASAP and resolve the issue

# # Please consider providing a thumbs up to this question if it helps you. by doing that, you will help other students who are facing a similar issue.

#---------------------------------------------------------------------------

# the required method

def remove_letter(letter, string):

    # initlaizeing output string

    output=""

    # loops over the lenght of the string

    for i in range(len(string)):

        #checks if the letter at the current index not equals letter

        if((string[i]).lower()!=letter.lower()):

            # appends to the output string

            output+=string[i]

    return output

#-----------------------------------------------------------------------------------

# the required method def remove_letter(letter, string): # initlaizeing output string output= # loops over the lenght of th

#------------------------------------------------------------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
In Python 1 2 Write a function that removes all occurrences of a given letter from...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python program (remove_first_char.py) that removes the first character from each item in a list...

    Write a Python program (remove_first_char.py) that removes the first character from each item in a list of words. Sometimes, we come across an issue in which we require to delete the first character from each string, that we might have added by mistake and we need to extend this to the whole list. Having shorthands (like this program) to perform this particular job is always a plus. Your program should contain two functions: (1) remove_first(list): This function takes in a...

  • i am trying to write a subroutine in assembly that removes all occurrences of a given...

    i am trying to write a subroutine in assembly that removes all occurrences of a given character in a string. The subroutine takes two parameters: the string pointer, and the character to be removed. Write a C code that calls this subroutine. The string is defined in the C source code file as global. Assume the assembly and C code are in separate files. Use Keil/uVision to test your program where the C code should ask the assembly subroutine to...

  • myDictionary= {1:"Apple", 2:"Mango", 3:"Banana"} 2POINTS write a PYTHON code that removes Apple from the myDictionary, is...

    myDictionary= {1:"Apple", 2:"Mango", 3:"Banana"} 2POINTS write a PYTHON code that removes Apple from the myDictionary, is this possible? explain write a PYTHON code that inserts Grape into the myDictionary, is this possible? explain write a PYTHON code that removes 3 from myDictionary, is this possible? Explain

  • Write a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified...

    Write a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified letter in a string. This function has to be recursive; you may not use loops!   CodeRunner has been set to search for keywords in your answer that might indicate the use of loops, so please avoid them. For example: Test Result text = 'welcome' letter = 'e' result = freq_of(letter, text) print(f'{text} : {result} {letter}') welcome : 2 e and A list can be...

  • Write a function that, given a word and a set of characters, filters all occurrences of...

    Write a function that, given a word and a set of characters, filters all occurrences of those characters from the word. For e.g. remove_chars("abcdeeeeefmnop", "ebo") returns: acdfmnp i.e all occurrences of e, b and o have been removed from abcdeeeeefmnop You should acquire the word and set of characters both from the user and then pass them to the function. Note: std::cin terminates when it encounters a space, you should take the word and character set as separate inputs: std::cin...

  • 3. Write Python statements that will do the following: a) Input a string from the user....

    3. Write Python statements that will do the following: a) Input a string from the user. *** Print meaningful messages along with your output.* b) Print the length of the String. Example input: The sky is blue. Correct output: The length of the string is 16 Incorrect output: 16 c) Print the first character of the string. d) Print the last character of the string. 4. Save the program. Double-check the left edge for syntax errors or warning symbols before...

  • Write a python function that takes in a string to use as a prompt and shows...

    Write a python function that takes in a string to use as a prompt and shows it to the user. Then get input from the user. If they entered a single sign out of the set +,-,*,/,% return it. If they entered anything else, give them a warning: “You may only enter one of the characters: +- * /%” and then repeat until they enter a correct option.

  • ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and...

    ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and including the given value. This function has to be recursive; you may not use loops! For example: Test Result print('%d : %d' % (5, sum_up_to(5))) 5 : 15 Q2, Write a recursive function that counts the number of odd integers in a given list. This function has to be recursive; you may not use loops! For example: Test Result print('%s : %d' % ([2,...

  • Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is...

    Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...

  • . Use what you learned from our First Python Program to write a Python program that...

    . Use what you learned from our First Python Program to write a Python program that will carry out the following tasks. Ask user provide the following information: unit price (for example: 2.5) quantity (for example: 4) Use the following formula to calculate the revenue: revenue = unit price x quantity Print the result in the following format on the console: The revenue is $___. (for example: The revenue is $10.0.) . . Use the following formula to calculate the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT