I am not having much success with Reverse in Practice makes Perfect. Please would someone kindly help me understand why my code does not work. Currently it runs fine until I try to actually reverse. When I try and run on ‘abc’ it becomes ‘cbc’.
Most strangely, the tuple/‘holders_holder’ changes its charecters and i do not know why this is.
Many thanks in advance!
Here is my code:
def reverse(text): #make a holder list holder =  for i in range(0,len(text)): #standard itterate through and append. Making the text into a list holder.append(text[i]) # make a dummy of the holder so that as 'holder' changes, the original list doesnt holders_holder = holder #holders_holder was not working and so i made it into an 'unmutable/changeable' tuple tuple(holders_holder) #check prints - everything is fine up to the end of the prints! here print (holders_holder) print (holder) print (len(holder)) print (len(text)) #two iteration variables... x = len(text) j = 0 #while loop. We want to switch the first (0th) charecter of holder with the last in holders_holder #thus the j iterating up and the x iterating down # note that the index of holders_holder needs a -1 because otherwise the range would be outside #of the index (i.e. leng = 3 but iterations need to be 0, 1 ,2... while j < len(text): holder[j] = holders_holder[x-1] print (holder) print (holders_holder) j += 1 x -= 1 reverse('abc')