You print the letters of the translated word as you go, I would recommend returning the translated word from the function instead. The fact that you see None printed behind your translated word is because inside the function you print the word, and outside the function you print the result of the function. The function has no result (no return
statement) and the default is None. Printing this leads to the None being appended at the end of the string that was already printed inside the function.
I would recommend a restructuring of translate_string
like this:
def translate_string(string):
translated_letters = [secret_translate(letter) for letter in string]
return("".join(translated_letters))
trans_string = translate_string("arizona")
print(trans_string)
'nevmban'
This solution uses a list comprehension to loop over the letters of the input string, no need for an explicit loop with a counter. List comprehensions are very nice, they do need some getting used to. In addition, the function now returns the string instead of printing it inside the function. The None is gone, and you can use the translated string further along in your program, e.g. as input to another function.