Given two strings(S1 and S2), write a program to determine if a string S2 is a rotation of another string S1.
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))
Comments
Leave a comment