+ 3
Given a string as input, use recursion to output each letter of the strings in reverse order, on a new line.
I have tried lot to reverse the input of 'PYTHON' but I didn't get the output. I also tried the hint given: spell() but it doesn't work out. Can someone help me.
37 Answers
+ 21
def spell(txt):
#your code goes here
if txt=="":
return txt
else:
print(txt[len(txt)-1])
return spell(txt[0:len(txt)-1])
txt = input()
print(spell(txt))
This code is correct for spelling backwards
+ 16
def spell(txt):
#your code goes here
if txt=="":
return
else:
print(txt[-1])
return spell(txt[:-1])
txt = input()
spell(txt)
+ 7
def reverse(text):
n = len(text)
if n:
print(text[-1])
if 1 < n:
reverse(text[:-1])
reverse('PYTHON')
+ 5
def spell(txt):
#your code goes here
while len(txt) > 0:
print(txt[-1])
return spell(txt[:-1])
txt = input()
spell(txt)
+ 3
def spell(txt):
#your code goes here
if len(txt)==0:
return 1
else:
print(txt[(len(txt)-1)])
return spell(txt[0:(len(txt)-1)])
txt = input()
spell(txt)
+ 2
Thanks for your answer dude. But I didn't get the answer. It was given *Complete the recursive spell() function to produce the expected result*
+ 2
def spell(txt):
x = len(txt)
for a in range(0,x):
print(txt[x-1])
x-=1
txt = input()
spell(txt)
+ 2
Shortest code with recursion :
def spell(txt):
if len(txt)==1:
print(txt)
else:
print(txt[-1]
spell(txt[:-1])
txt = input()
spell(txt)
+ 2
def spell(txt):
#your code goes here
if txt == "":
return txt
else:
print(txt[len(txt) - 1])
return spell(txt[0:len(txt) - 1])
txt = input()
spell(txt)
+ 2
def spell(txt):
#your code goes here
if txt=="":
return txt
else:
print(txt[len(txt)-1])
return spell(txt[0:len(txt)-1])
txt = input()
print(spell(txt))
+ 2
def spell(txt):
#your code goes here
if txt=="":
return txt
else:
print(txt[len(txt)-1])
return spell(txt[0:len(txt)-1])
txt = input()
print(spell(txt))
+ 2
def spell(txt):
Print(txt[::-1]
txt= input()
spell(txt)
+ 1
def spell(txt):
#your code goes here
x = len(txt)
for a in range(0,x):
print(txt[x-1])
x-=1
txt = input()
spell(txt)
+ 1
def spell(txt):
#your code goes here
if txt == "":
return txt
else:
return txt[::-1]
txt = input()
print(spell(txt))
+ 1
dude stop using for loops the question is asking for recursion
+ 1
my_str = (input ())
my_list = list(my_str)
my_list2 = my_list [::-1]
my_list3 = '\n'.join(my_list2)
print(my_list3 )
#simple, no complications
0
just change 'reverse' by 'spell'
0
#Answer this question
def spell(t):
X = []
for i in t:
X.append(i)
r = len(X) -1
while r>-1:
print(X[r])
r -= 1
txt = input()
spell(txt)
0
def spell(txt):
output = “”
for i in range(len(txt)):
output += txt[(len(txt)-i)-1] + “\n”
print(output)
An easier way to go about it. This method appends the last element of the word to the output string also adding a new line space. Achieves same output!
0
But all you have to do it with recursion where is it?