Ask Question
13 August, 23:11

write a recursive function def reverse (string) that computes the reverse of a string. For example, reverse ("flow") should return "wolf" Hint: reverse the substring starting at the second character, then add the first character at the end

+1
Answers (1)
  1. 14 August, 00:04
    0
    def reverse (s):

    if (len (s) >1):

    return reverse (s[1:]) + s[0]

    else:

    return s

    print reverse ("flow")

    Explanation:

    The reverse of a string is the reverse of the substring starting at the 2nd char, followed by the first char. Of course you always need a stop criterium to end the recursion. Only recurse if the string has at least 2 characters.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “write a recursive function def reverse (string) that computes the reverse of a string. For example, reverse ("flow") should return "wolf" ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers