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)
Comments
Post a Comment