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
  • 7,452
  • 5
  • 27
  • 43
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
  • 33,459
  • 6
  • 59
  • 67