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

2019 wasn’t just a year—it was a whole era.From lectures to late nights, chaos to clarity… every frame built a story I’m still living ✨

Video Link The video contains snaps from 2019 throwback ones when i was doing my masters studies from university of surrey, guildford, londo...