I tried to reverse the string using following code !
def rev_string(text):
a = len(text)
for i in range(a,0,-1):
print(text[i])
rev_string("Hello")
It shows the following error:
Traceback (most recent call last):
File "rev_str.py", line 5, in <module>
rev_string("Hello")
File "rev_str.py", line 4, in rev_string
print(text[i])
IndexError: string index out of range
I also tried this code But the last character of the string couldn't be printed.
def rev_string(text):
a = len(text)
for i in range(a-1,0,-1):
print(text[i])
rev_string("Hello")
Output:
python3 rev_str.py
o
l
l
e
Anyone, please help!