Try just:
reverse(hello)
In fact with
print reverse(hello)
you are printing the return value of reverse. And that return value is None.
Let me give you few general advises:
reverse() in your code is a function with side effects (printing). You should avoid
functions with side effects when you don't need, consider having reverse() returning the word instead of printing it:
def reverse(letters):
backwards = ""
i = len(letters) - 1
while i >= 0:
backwards = backwards + letters[i]
i = i - 1
return backwards
print (reverse("hello"))
Moreover
i = len(letters) - 1
while i >= 0:
backwards = backwards + letters[i]
i = i - 1
is not easy to mantain and if you add functionality to the loop the decrement i=i-1 will be far from the place where it should 'conceptually' be. You should prefer having decrement together with the check:
for i in xrange(len(letters)-1,-1,-1):
backwards = backwards + letters[i]
When I'm lazy I write
myString = myString + fewChars
so I can understand you being lazy. But adding fewChars does not modify myString but creates a new one. If you are iteratively adding many chars, rarely the most efficient way is to add one by one. Consider using join().
For instance
letters = 'word'
lettersList = [letters[i] for i in xrange(len(letters)-1,-1,-1)]
myReversed ''.join(lettersList)
ok I agree is not readable and probably not even faster, but for larger strings it scales better than a newString = oldString + oneChar approach.
That said, more pythonic approaches
letters[::-1]
already suggested by someone faster than me typically works much better and are easy to be read by python programmers.