Problem in my code

Problem in my code
0

Hi dear coders! Please help! I can recognize the error in my code

text = "this is not a reversed text"

def reverse(x):
    #complete this function so that it takes string x as an input 
    #and returns its reverse
    text = str(input("Enter your text:"))
    index = -1
    output = []
    while index >= -len(text):
        output.append(text[index])
        index -= 1
    output = "".join(output)
    

    


print("the reversed text is: "+reverse(text))

did you call the function?

yes nd I get back this error:
TypeError: must be str, not NoneType

you can send me the complete code so that i can check and see

that was the full code, I ran it on anaconda editor

Now try again:

text = “this is not a reversed text”

def reverse(x):
#complete this function so that it takes string x as an input
#and returns its reverse
text = str(input(“Enter your text:”))
index = -1
output =
while index >= -len(text):
output.append(text[index])
index -= 1
output = “”.join(output)

print("the reversed text is: ",reverse(text))

1 Like

the reversed text is: None
this is the output that I just got

what does the square stand for?

list that’s what it stands for

is it square brackets “” ?

did that worked in your editor?

Try this:
I found in this question on stackoverflow: link

text = "this is not a reversed text"

def reverse(x):
    #complete this function so that it takes string x as an input 
    #and returns its reverse
    text = str(input("Enter your text:"))
   
    length = len(text)
    index = length -1
    reversed_text = ''
    while index >= 0:
      letter = text[index]
      reversed_text += letter
      index = index -1 


    print (reversed_text)
    

    

#text = str(input("Enter your text:"))
print("the reversed text is: ", reverse(text))
1 Like

thnx a lot! that works

1 Like

You are welcome @walx ! I’m also learning Python and sometimes I struggle too. :grinning:

1 Like