9/9/22

Spelling 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

def spell(txt):

    #your code goes here

    if len(txt) == 0:

        return

    temp = txt[0]

    spell (txt[1:])

    print(temp , end ='' )

txt = input()

spell(txt)



Blog Archive