Answer to Question #231384 in Python for bhuvana

Question #231384

Given two strings(S1 and S2), write a program to determine if a string S2 is a rotation of another string S1.


1
Expert's answer
2021-09-10T23:52:07-0400
string1=input("Enter the first string: ")
string2=input("Enter the second string: ")
R =0
temp=string1
NoRotation=False
while temp!=string2:
    R+=1
    temp = string1[len(string1) - R:] + string1[0 : len(string1) - R]
    if(R>=len(string1)):
        temp=string2
        NoRotation=True
if NoRotation:
    print("No rotation")
else:
    print(str(R))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS