String rotation in python assignment

 Harry  August 28, 2022

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at Thank you

String Rotation

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

Input

The first line of the input will be a string S1.

The second line of the input will be a string S2.Output

If string S2 is a rotation of another string S1, print number of right rotations made by string S1 to match the string S2. Otherwise, print "No Match".

Where right rotation means all elements are moving towards the right side by one place where the last element will be placed in the first place example, one right rotation of "python" is "npytho"

For example, if the given strings S1 and S2 are "python" and "onpyth",

The first right rotation of s1 is "npytho" which is not equal to string S2"onpyth"

The second right rotation of s2 is "onpyth" which is equal to string S2 "onpyth".

So output 2

Sample Input 1

python

onpyth

Sample Output 1

2

Sample Input 2

Python

Python

Sample Output 2

String Rotation

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

Input

The first line of the input will be a string S1.

The second line of the input will be a string S2.Output

If string S2 is a rotation of another string S1, print number of right rotations made by string S1 to match the string S2. Otherwise, print "No Match".

Where right rotation means all elements are moving towards the right side by one place where the last element will be placed in the first place example, one right rotation of "python" is "npytho"

For example, if the given strings S1 and S2 are "python" and "onpyth",

The first right rotation of s1 is "npytho" which is not equal to string S2"onpyth"

The second right rotation of s2 is "onpyth" which is equal to string S2 "onpyth".

So output 2

Sample Input 1

python

onpyth

Sample Output 1

2

Sample Input 2

Python

Python

Sample Output 2

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    Given a string of size n, write functions to perform following operations on string.

    1. Left [Or anticlockwise] rotate the given string by d elements [where d

    Chủ Đề