replacement without any imports or built in functions?
<p>This is a homework question. I'm defining a function that takes a word and replaces a given char by another char. For example replace("cake","a","o") should return "coke" I have tried</p>

<pre><code>def replace(word,char1,char2):
    newString = ""
    for char1 in word:
        char1 = char2
        newString+=char1
    return newString  #returns 'oooo'
</code></pre>

<p>and</p>

<pre><code>def replace(word,char1,char2):
    newString = ""
    if word[char1]:
        char1 = char2
        newString+=char1
    return newString  #TypeError: string indices must be integers, not str
</code></pre>

<p>I'm assuming my first attempt is closer to what I want. What is going wrong in my functions?</p>
