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 first string here: ')
string2 = input('Enter second string here: ')
comb_string = string1 + string1
if len(string1) == len(string2):
if comb_string.count(string2) > 0:
print('{} is a rotation of {}'.format(string2, string1))
else:
print('{} is not a rotation of {}'.format(string2, string1))
else:
print('{} is not a rotation of {}'.format(string2, string1))
Enter first string here: AACD
Enter second string here: ACDA
ACDA is a rotation of AACD
Enter first string here: DAVID
Enter second string here: GARRY
GARRY is not a rotation of DAVID
Comments
Leave a comment