0

I tried this code but I don't know how input the characters one per line and how to stop the input sequence with the character 0.

def reverse(string):
    if len(string) == 0:
        return string
    else:
        return reverse(string[1:]) + string[0]
a = str(input())
print(reverse(a))
Vlad
  • 8,225
  • 5
  • 33
  • 45
d.fox3
  • 1

1 Answers1

2

In python you can usually reverse an iterable with [::-1]. It should work on strings as well, I guess. So: 'hello'[::-1] gives 'olleh'.

ggorlen
  • 44,755
  • 7
  • 76
  • 106