Spelling Backwards in python | Sololearn: Learn to code for FREE!

-1

Spelling Backwards in python

Hi i was doing a code project of the intermediate python course and i have already solved it but my question is: Is there a way to print the text backwards without changing it? like printing it as the function runs =================================================================== NEXT IS THE CODE PROJECT STATEMENT: 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 Complete the recursive spell() function to produce the expected result. =================================================================== MY SOLUTION: def spell(txt): #your code goes here def reverse(txt): if len(txt) == 0: return txt else: return reverse(txt[1:]) + txt[0] txt = reverse(txt) for i in txt: print(i) return txt = input() spell(txt) =================================================================== I would like to know how you would have solved it or other ways to solve that problem

5/28/2022 6:00:45 PM

Kevin Steling

2 Answers

New Answer

0

for i in input()[::-1]: print(i)

0

No loop or recursion required: def reverse(txt): return txt[::-1] ----- Short version of your program: print(*list(input()[::-1]), sep='\n') Input: HELLO Output: O L L E H