15.7 reverse


This won’t work. Please explain where the error is.

def reverse(s):
  word = []
  for i in range(len(s)):
    i -= 1
  word = ' '.join(word)
  return word


Should mention that I had the indents correct, not sure why each line aligned left when I copied the code.




currently you are appending integers to word, you want to access s by index (to get the letters) to append to the list

to access a string by index we have the following general syntax:


isn’t it easier to check documentation on range() function? with 3 arguments, range can loop backwards over a string


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.