Question: This is Python Write a function replace_letter(word, letter, replacement) that takes in a string word and returns a new string representing word with all instances

This is Python

Write a function replace_letter(word, letter, replacement) that takes in a string word and returns a new string representing word with all instances of the letter letter replaced by the letter replacement.

For example, replace_letter('area', 'a', 'o') should return the string 'oreo'. You may assume that word is non-empty, and that letter and replacement are both strings of length 1 (they are valid single letters). Note: case-sensitivity matters, so 'B' is a different letter than 'b'. You may not use the Python function replace().

Here are few examples that your function will be expected to produce:

  • replace_letter('area', 'a', 'o') should return 'oreo'
  • replace_letter('mississippi', 's', 'z') should return 'mizzizzippi'
  • replace_letter('nothing', 'z', 'a') should return 'nothing'

These are not the only cases that will be used to test your function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!