Write a Python program (with comments) to do the following: a Define a function
ID: 3807211 • Letter: W
Question
Write a Python program (with comments) to do the following: a Define a function replace_abc (str1, char1) that takes a string str1 and a single character char1 as input. The function returns an updated string, where all occurrences of the letters 'a', 'b', or 'c' have been replaced by char1 b Define a variable mystr = "It is a book about abc's" and print mystr c. Call the above function with the string mystr and the single character '*' as inputs and print the value of returned by the function. A sample output is shown below.Explanation / Answer
# link for code in case indentation messup: https://goo.gl/KvFgJk
def replace_str(str1, char1):
return str1.replace('a', char1).replace('b', char1).replace('c', char1)
mystr = "It is a book about abc's"
print mystr
mystr = replace_str(mystr, '*')
print mystr
Sample run
$ python main.py
It is a book about abc's
It is * *ook **out ***'s
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.