I've created a small test for a bigger function I am trying to create. Right now I have a function that should take a string as input, locate and replace the letter 'a' with the upside-down version within the string, and return a new string containing the edited version of the old string. For some reason, however, when I attempt to run this function, the loop takes effect on the first letter of the string, but then breaks and fails.
I've run the code in the function in the IDLE3 REPL and it works fine. I'm trying to figure out why it doesn't translate into a function.
def upside_down(word):
new_word = [] # Empty list for creating the edited string.
for letter in list(word): # Splitting the string into a list and looping through.
if letter == 'a':
new_word.append('\N{LATIN SMALL LETTER TURNED A}')
else:
new_word.append(letter)
return ''.join(new_word) #Should return the new edited string.
As I said, I should be able to access the function like this:
upside_down('cab')
and receive this as an output:
'cɐb'