# Output is good..but code isn't working

#1

This is what my code shows when executed…Oops, try again. Did you create a function called reverse? Your code threw a “global name ‘reverse’ is not defined” error. While my console shows the correct output, as expected which is !nohtyP in this case.

``````

s = "Python!"
n = range(len(s))
m = []
def lists():
for x in n:
m.append(x+1)
return m
lists()
a = s[-1:]
z = []
def spam():
for l in n:
f = s[-(l+1):-l]
z.append(f)
return z
spam()
z.remove('')
z.insert(0, a)
h = "".join(z)
print h

``````

#2

your function must be named `reverse`, the exercise expects this of you (its in the instructions: Define a function called reverse)

#3

OK. I have defined a ‘reverse’ function.Now my code looks like this…

``````s = str(raw_input("Give your string: "))
n = range(len(s))
m = []
def reverse(text):

def lists():
for x in n:
m.append(x+1)
return m
lists()
a = s[-1:]
z = []
def spam():
for l in n:
f = s[-(l+1):-l]
z.append(f)
return z
spam()
z.remove('')
z.insert(0, a)
h = "".join(z)
print h
print reverse(s)
``````

AND ITS STILL NOT LETTING ME PASS TO NEXT EXERCISE…SHOWING THE SAME ERROR
THANKS FOR HELP…

#4

ensure your function works for any string supplied at function call:

``````print reverse(s)
print reverse("Python!")
``````

not only `s`, it should also work for `"Python!"` (and more)

furthermure, your function only prints the reversed string, look at the instructions:
For example: reverse(“abcd”) should return “dcba”.

i highlighted a very important word for you in that sentence

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.