Reverse a string, in Python

python

#1

Hello everyone. In reverse section I typed some code but it isn’t working and also there is no error. Here is the code:

def reverse(text):
  a = []
  count = len(text)
  while count > 0:
    a.append(text[count-1])
    count -= 1
  return "".join(a)

By the way it is working ubuntu terminal.


#2

define isn’t working?

Remember that if you want to see the function in action, you need to call the function (functions only execute when called)


#3

By saying working actually I want to say the system is not accepting it as a correct answer. When I try to print something, it does not work on the website but it is working on terminal.


#4

i ran your code, and its accepting. Weird, maybe refresh the page. And there are no error messages of any kind? Can i see a screenshot of the full page


#5

I tried refreshing and I tried it many times but it didn’t work then. However, the same code just worked out now. It is really weird… Whatever, thanks for your help :slight_smile:


#6