0

Can i have explanations as directive ?

Speeling backwards Given a string as input, use recursion to output each letter of the strings in reverse order, on a new line. Sample Input HELLO Sample Output O L L E H

29th Oct 2021, 11:41 AM
ola Scar
ola Scar - avatar
2 Answers
+ 3
Given the string s = 'HELLO' the individual characters can be obtained through the use of an index print(s[0]) // Outputs 'H' The problem requires you to use recursion, so that's tricker than just looping and printing the letters from the back. A possible implementation would be to have a function which takes an input string, pop the last character of the string, and pass the remaining string to a recursive call. E.g. recur('HELLO') // output 'O' recur('HELL') // output 'L' recur('HEL') // output 'L' ... etc You'll need some knowledge on getting substrings out of strings: https://stackoverflow.com/questions/663171/how-do-i-get-a-substring-of-a-string-in-JUMP_LINK__&&__python__&&__JUMP_LINK
29th Oct 2021, 12:07 PM
Hatsy Rei
Hatsy Rei - avatar
0
Thanks Rei
8th Nov 2021, 12:22 PM
ola Scar
ola Scar - avatar