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