-3
def translate(phrase):
    translated_word = phrase
    for letter in phrase:
        if letter == "a":
            translated_word.replace(letter, "1", 1)
    print(translated_word)
         
            
print(translate(input("Enter: ")))

Output: None
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45
vdiqbd
  • 1

2 Answers2

3
def translate(phrase):
    translated_word = phrase
    translationDict = {
        'a': '1'
    }
    for k,v in translationDict.items():
        translated_word = translated_word.replace(k, v)
    return translated_word
         
            
print(translate('dupa'))
Vulwsztyn
  • 2,140
  • 1
  • 12
  • 20
1

I’m not sure why you try to write a function to do that. The standard string method replace() already does what you want:

print(input("Enter: ").replace("a", "1"))

Note that the replace() method does not change the string (strings are immutable), but instead it returns a new string.

inof
  • 465
  • 3
  • 7