#handles getting strings from the front
#Jerry Lan
#West Chester East High School
# Senior 5 Division
# ACSL Ascending Strings
def front(num, nfor, nback, temp):
#handles getting the string from the back
def back(Num, Nfor, Nback, Temp):
while (int(Nback) <= int(Nfor) and Temp != len(Num)):
Temp +=1
Nback = Num[len(Num)-Temp:]
#use step substring to reverse string by calling steps of -1
Nback = Nback[::-1]
#if the number retrieved from the while loop process is greater, print it, trim, and call forward function
if int(Nback) > int(Nfor):
Num = Num[0: len(Num)-Temp]
Temp = 0
print (int(Nback), end = " ")
front(Num, Nfor, Nback,Temp)
else:
#return zero to finish recursion and move to next input
return 0
while (int(nfor) <= int(nback) and temp != len(num)):
temp+= 1
nfor = num[0: temp]
#if the forward number is larger than the previous backward number, print it, trim the number, and call the back
if int(nfor) > int(nback):
num = num[temp:]
temp = 0
#print integer version of nfor in order to remove leading zeros
print (int(nfor), end = " ")
#call back function with updated values
back(num, nfor, nback, temp)
else:
return 0
for x in range (0, 5):
num = input("Enter number: ")
front(num, "0", "0", 0)
print()