I need to write a function that takes a string as an argument and outputs the letters backward, one per line.so far I have this:

def wordReverse(word):
	acum = ""
	for ch in word:
		acum = ch + acum
	return acum

I tried adding \n to acum but an error occurs.Where should I put it?

nevermind. I got it. here's what I did:

def wordReverse(word):
	acum = ""
	for ch in word:
		acum= ((ch)+"\n") + acum
	print acum
def wordReverseToLines(word):
  for i in range(len(word)-1,-1,-1):
    print (word[i])
# or
def wordReverseUsingList(word):
  arr = [x for x in word]
  arr.reverse()
  print ("\n".join(arr))

nevermind. I got it. here's what I did:

def wordReverse(word):
	acum = ""
	for ch in word:
		acum= ((ch)+"\n") + acum
	print acum

Great, very nice solution!

You can use Python built-in functions to simplify it a little ...

def wordReverse(word):
    for ch in reversed(word):
        print ch

wordReverse("python")

And for the beauty of recursion you can try:

def wordReverse(word):
    if not word:
        return word ## empty sequence is already reversed
    else:
        return word[-1]+wordReverse(word[:-1])

print wordReverse('Python newbie')

And the classic "vegaseat's"

def wordReverse(word):
    return word[::-1] # -1 step from default start to default end
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.