0

Spelling Backwards

I need help on the spelling backwards challenge.

1st Apr 2022, 3:55 PM
Baybassos
11 Antworten
+ 9
def spell(txt): #your code goes here if txt=="": return else: print(txt[-1]) return spell(txt[:-1]) txt = input() spell(txt)
2nd Apr 2022, 3:24 AM
Ajit Kumar
Ajit Kumar - avatar
+ 4
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))
28th Jul 2022, 8:46 AM
Neupane Dev
Neupane Dev - avatar
+ 3
Ilyas Guissous , please also put your code in playground, save it and post the link to this file here. thanks!
1st Apr 2022, 4:31 PM
Lothar
Lothar - avatar
+ 2
Use [::-1] Example: Str = str(input()) print(Str[::-1]) ******************************* There is another way: Str = str(input()) List = list(Str) List_reverse = List[::-1] for i in List_reverse: print(i)
1st Apr 2022, 4:53 PM
Beh
Beh - avatar
+ 2
def spell(txt): #your code goes here x=len(txt) #x is length of string if x==0: return txt else: print(txt[-1]) return spell(txt[0:x-1]) #colon operater is important to slice the string txt = input() spell(txt)
31st Jul 2022, 7:17 PM
SANDA JAYA PRAKASH
+ 1
Language?? And what to do? (elaborate it)
1st Apr 2022, 3:56 PM
JOKER
JOKER - avatar
+ 1
it seems to be the *intermediate python* tutorial exercise 19. the task description is: Given a string as input, use recursion to output each letter of the strings in reverse order, on a new line. Sample Input HELLO Sample Output O L L E H Complete the recursive spell() function to produce the expected result
1st Apr 2022, 4:35 PM
Lothar
Lothar - avatar
+ 1
Beh , your codes are not both absolutely correct, since the first one outputs the string in one line. but following the task description this task should be done with a recursive function.
1st Apr 2022, 5:22 PM
Lothar
Lothar - avatar
0
def spell(txt): #your code goes here if len(txt) == 0: return 0 else: for ch in range(len(txt),0,-1): ch-=1 print(txt[ch]) txt = input() spell(txt) #For some reason they added a new line for each letter in the input. Because they don't wanna make it easy.
1st Oct 2022, 2:53 AM
Dragon RB
Dragon RB - avatar
0
Thanks everyone!
31st Oct 2022, 8:37 PM
Baybassos