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

+4

Spelling backwards in python project?

2/22/2021 1:06:22 PM

Michael Gonzalez

32 Answers

New Answer

+28

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

+12

string[::-1]

+6

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

+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

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

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

+2

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

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

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

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

-1

def spell(txt): #your code goes here c=str(txt) print (c[::-1]) txt = input() spell(txt)

-1

So "to output each letter of the strings" is a pure iterative task but not recursive. Please contact "Intermediate Python" author.

-1

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)