Spelling backwards in python project? | Sololearn: Learn to code for FREE!

+5

# Spelling backwards in python project?

2/22/2021 1:06:22 PM

Michael Gonzalez

+38

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))

+14

string[::-1]

+7

def spell(txt): print(txt[::-1]) txt = input() spell(txt)

+6

With Recursive, def spell(txt): if txt == "": return txt else: print(txt[- 1]) return spell(txt[0:len(txt) - 1])

+3

def reverse(text): if text: print(text[-1],end="") reverse(text[:-1]) # remove 'end' argument if you need each character on its own line ;)

+3

def spell(txt): #your code goes here if txt == "": return txt else: print(txt[-1]) return spell(txt[:len(txt) - 1]) txt = input() spell(txt)

+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]

+1

def spell(txt): for x in range(1,len(txt)+1): print(txt[-x]) txt = input() spell(txt)

+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)

+1

txt = input() print(txt[::-1])

+1

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

+1

def spell(txt): #your code goes here word = txt[::-1] for i in word: print(i) txt = input() spell(txt)

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...

0

If you mean the end of module project, mind that the task instruction asks us to use recursion.

0

def spell(txt): v = reversed(list(txt)) for i in v: print(i) txt = input() spell(txt)

0

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.

0

def spell(txt): y=reversed(txt) for i in y: print('\n'.join(i)) txt = input() spell(txt)

0

def spell(txt): #your code goes here x = len(txt) y = list(txt) i = int(x - 1) while i>=0 : yield y[i] i -=1 txt = input() spell(txt) for i in spell(txt): print(i)

0

I didn’t think of how to do it using recursion, I decided like this: def spell(txt): txt = txt[::-1] for i in txt: print(i)

0

How to understand that in order to get the last character of a word, you need to subtract one.