+ 5

Spelling backwards in python project?

22nd Feb 2021, 1:06 PM
Michael Gonzalez
Michael Gonzalez - avatar
48 Respuestas
+ 45
Try this code: 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))
23rd Feb 2021, 2:39 PM
Niviedha shekor
Niviedha shekor - avatar
+ 17
string[::-1]
22nd Feb 2021, 1:15 PM
visph
visph - avatar
+ 14
def spell(txt): print(txt[::-1]) txt = input() spell(txt)
29th Apr 2021, 10:09 AM
Zakaria Ibn Said
+ 11
def spell(txt): #your code goes here if txt == "": return else: print(txt[-1]) return spell(txt[:len(txt) - 1]) txt = input() spell(txt)
3rd Mar 2022, 9:56 PM
IbrahimCPS
IbrahimCPS - avatar
+ 7
With Recursive, def spell(txt): if txt == "": return txt else: print(txt[- 1]) return spell(txt[0:len(txt) - 1])
4th Nov 2021, 12:19 PM
Yasir NV
Yasir NV - avatar
+ 4
def reverse(text): if text: print(text[-1],end="") reverse(text[:-1]) # remove 'end' argument if you need each character on its own line ;)
22nd Feb 2021, 6:21 PM
visph
visph - avatar
+ 3
def spell(txt): i = len(txt) while i > 0: yield txt i -= 1 txt = input() for i in txt[::-1]: spell(i) print(i) spell(txt) I know this seems less efficient but it does seem like what it wants considering the lessons
27th Dec 2021, 7:19 PM
John
+ 2
You can that the reverse of it like you would with a normal list using the slice operator: list[start:stop:step] So to reverse: list[::-1]
22nd Feb 2021, 1:15 PM
Angelo
Angelo - avatar
+ 2
If you want to reverse the spelling of a string in Python, you can use slicing. Here's a simple example: ```python word = "example" reversed_word = word[::-1] print(reversed_word) ``` This will output: ``` elpmaxe ``` In the example, `word[::-1]` uses slicing to reverse the string `word`. If you want to reverse the spelling of a word in a larger context within a project, you can incorporate this logic accordingly.
8th Jan 2024, 2:32 AM
𝐀𝐲𝐞𝐬𝐡𝐚 𝐍𝐨𝐨𝐫
𝐀𝐲𝐞𝐬𝐡𝐚 𝐍𝐨𝐨𝐫 - avatar
+ 1
If you mean the end of module project, mind that the task instruction asks us to use recursion.
22nd Feb 2021, 6:14 PM
Lisa
Lisa - avatar
+ 1
def spell(txt): for x in range(1,len(txt)+1): print(txt[-x]) txt = input() spell(txt)
29th Apr 2021, 10:07 AM
Zakaria Ibn Said
+ 1
I tried with Stack: def spell(txt): #your code goes here txt = list(txt) for l in range(len(txt)): print(txt.pop()) txt = input() spell(txt)
4th Aug 2021, 3:52 PM
Walter Steven Gaitan Gutierrez
Walter Steven Gaitan Gutierrez - avatar
+ 1
this is like an adaptation from a code I already saw here, I made it shorter, and I'll add comment to the steps to explain the code. here it goes. def spell(txt): if txt ==' ' #if txt is empty return None #show nothing else: print(txt[-1]) #print last character return spell(txt[:-1]) #run the fuction again this time without the last character , and keep doing that till it's empty.
26th Dec 2021, 4:02 PM
Gideon
Gideon - avatar
+ 1
def spell(txt): #your code goes here word = txt[::-1] for i in word: print(i) txt = input() spell(txt)
19th Jan 2022, 3:44 PM
Fra Cat
Fra Cat - avatar
+ 1
def spell(txt): #your code goes here if txt == "": return 0 else: print(txt[-1]) txt = txt[:-1] spell(txt) txt = input() spell(txt)
8th Sep 2022, 3:00 AM
Xiaoxing Liu
+ 1
def spell(txt): #your code goes here if txt != "": print(txt[-1]) spell(txt[:-1]) txt = input() spell(txt) Probably the easiest while still being recursive
21st Jan 2023, 7:16 PM
Yoshi likes trains
Yoshi likes trains - avatar
0
Username I may understand that you think using an external c++ code to call from python can (maybe) lead to higher performance, but the cost of writing, debugging and readability is really too high. Also, you are missing the part on how python can use that code... And it may be a little to advanced...
22nd Feb 2021, 1:46 PM
Angelo
Angelo - avatar
0
def spell(txt): #your code goes here testo = [] for x in txt: testo.append(x) for y in testo[::-1]: print(y) txt = input() spell(txt)
26th Jun 2021, 10:42 AM
Ale
Ale - avatar
0
gIves the expected result txt=input() j=len(txt)-1 for i in txt: print(txt[j]) j=j-1
13th Sep 2021, 10:26 AM
guenaizi abdelkader
guenaizi abdelkader - avatar
0
def spell(txt): v = reversed(list(txt)) for i in v: print(i) txt = input() spell(txt)
20th Dec 2021, 12:29 PM
print ("Moon")
print ("Moon") - avatar