Friday, February 5, 2021

Python program for reversing a string

First Method:


string = input("Enter a string:")

r = ""

l = len(string)

for a in range(l):

    r = r + string[l-a-1]

if(string == r):

    print(string, "is a palindrome")

else:

    print(string, "is not a palindrome")


Second Method: 


string = input("Enter a string:")

r = ""

length = len(string)

for a in range(-1, (-length-1), -1):

    r = r + string[a]

if(string == r):

    print(string, "is a palindrome")

else:

    print(string, "is not a palindrome")



No comments:

Post a Comment

All Quotes

Quote 55: Your brand grows through authentic achievements. Quote 54: Personal branding is clarity, consistency, and credibility. Quote 53: E...