Ask Question
18 October, 19:23

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

+4
Answers (1)
  1. 18 October, 22:57
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers