#!/usr/bin/python3
# ===================================================================
# reverse string using recursion
# ===================================================================
import user_interface as ui
# -------------------------------------------------------------------
# ---- recursive function - print the last character first
# -------------------------------------------------------------------
def print_reverse(lst,idx,max):
if idx < max:
print_reverse(lst,idx+1,max)
print(lst[idx],end='')
return
# -------------------------------------------------------------------
# ---- main
# -------------------------------------------------------------------
while(True):
s = ui.get_user_input('enter a string: ')
ss = s.strip() # strip string
if not ss:
break
lst = list(ss)
print_reverse(lst,0,len(lst)-1)
print()