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

23 Answers

New Answer

+19

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]

+5

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

+4

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]

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

+2

def spell(txt): for x in range(1,len(txt)+1): print(txt[-x]) 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): #your code goes here c=str(txt) print (c[::-1]) txt = input() spell(txt)

0

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

0

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

0

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

0

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)

0

Easy and understandable code..but a bit long. def spell(word, len): #your code goes here list = [] for i in word: list.append(i) while len>=1: print(list[len-1]) len-=1 word = input() len = len(word) spell(word,len)

0

gIves the expected result txt=input() j=len(txt)-1 for i in txt: print(txt[j]) j=j-1

0

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

-1

alguien que me envie el link del codigo porfa

-1

This also worked: word = input() def spell(txt): l=len(txt) for i in range(l,0,-1): print(txt[i-1]) spell(word) But I'm not sure it's a recursive function... 😆

-1

maybe this could be a more simple one:. def spell(txt): #your code goes here for i in txt[::-1]: print (i) txt = input() spell(txt)

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