Answer to Question #231104 in Python for bhuvana

Question #231104

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-08-31T00:53:07-0400
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

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