PYTHON CODE TO REVERSE A GIVEN STRING

  TO REVERSE A GIVEN STRING:

METHOD -1

BY LOOPING AND JUST VIEWING THE REVERSE TEXT

a=input("A:")

j=len(a)-1

for i in range(len(a)-1,-1,-1):

    print(a[i] ,end="")

OUTPUT-

METHOD-2

BY CREATING A NEW STRING 

s=input("text:")
c=""
for i in range(len(s)-1,-1,-1):
    y=s[i]
    c=c+y
print("The reverse of the given string is",c)

OUTPUT-


Comments

Popular posts from this blog

Sum of the digits present in a list

Python program to find hcf of two numbers

Python code to search a number in a sorted list