Question

Python code that Returns a COPY of string s1 with every instance of old_char in s1...

Python code that Returns a COPY of string s1 with every instance of old_char in s1 replaced by new_char

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. 

Let me know for any help with any other questions.

Thank You!

===========================================================================

def replace(s1, old_char, new_char):
    s1_copy = ''
    for letter in s1:
        if letter == old_char:
            s1_copy += new_char
        else:
            s1_copy += letter
    return s1_copy


def main():
    s1 = input('Enter a string: ')
    old_char = input('Enter the character you like to replace: ')
    new_char = input('Enter the character you like to replace with: ')

    print(replace(s1, old_char, new_char))


main()

==================================================================

1: Proj 1 2 3 def replace (31, old_char, new_char): 31_copy = for letter in sl: if letter == old_char: 31_copy += new_char el

Add a comment
Know the answer?
Add Answer to:
Python code that Returns a COPY of string s1 with every instance of old_char in s1...
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
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